This guide provides instructions for setting up and running the FastAPI project for document streaming.
Data Schema and OpenAPI docs is available in openapi.yaml file.
Make sure to install the following Python packages:
pip install kafka-python # Required for Kafka producer communication
pip install uvicorn[standard] # To host the server- Navigate to the
appfolder - Run the following command:
uvicorn main:app --reloadThis will start the FastAPI server with hot-reloading enabled.
- Ensure you've completed the Running FastAPI Locally section
- Install the following Python package:
pip install fastapi2postmanRun the following command in the same directory as your main.py:
fastapi2postman --app main.app --output doc_stream_postman.jsonThis will generate a Postman collection file named doc_stream_postman.json for API testing.
Run the following command to build the Docker image:
docker build -t api-ingest .This will create a Docker image named api-ingest.
You have two options for running the Docker container:
To run the container on the same network as other services:
docker run --rm --network document-streaming_default --name my-api-ingest -p port_num:port_num api-ingestTo run the container with just a port mapping to your local machine:
docker run --rm --name my-api-ingest -p port_num:port_num api-ingestThis option allows you to access the API from your local machine at http://localhost:80.
- The
fastapi2postmantool is useful for generating Postman collections, which can be imported into Postman for API testing. - When running the Docker container, the
--rmflag ensures that the container is removed after it stops, which is useful for development and testing. - The
-p port_num:port_numflag maps the container's port port_num to your host's port port_num. Adjust this if you need to use a different port on your host machine. - run
client/code/get_api_docs.pyto obtain the documentation in yaml format.
For more information on FastAPI, Docker, or Kafka, refer to their respective official documentation: