Interactive API at: www.inventoryapi.ducnguyen.dev/docs
- Python 3.8
- FastAPI
- MongoDB
- Docker and Compose
- CRUD Functionality. Users are able to:
- Create new item in the inventory
- View all items in the inventory
- View item by ID
- Delete item by ID
- Update item by ID
- Export all products in the inventory to a CSV file.
- Swagger UI auto generated from OpenAPI, allows visualizing and interacting with the API without a front-end.
- Async functionalities.
- Easy, extendable models and schemas.
- Schemas are validated by Pydantic.
- Wrapped
ObjectID
(_id
field) from MongoDB by a custom field, compatible with openapi standard. More information here. - Environment variables are parsed by
.env
, validated by Pydantic. - Containerized with Docker and Compose for easy deployment.
- pre-commit hook for auto linting before git commit.
- Api tests done by Pytest and Tavern.
- CI runs tests on push by GitHub Actions.
Clone the repo: git clone https://github.com/DukeNgn/inventory-tracking.git
cp example.env .env
to create environment file.- Change the content of the
.env
file to the local environment. For example:is a valid configuration for the default MongoDB.APP_NAME="Inventory Tracking API" MONGO_URI=mongodb://localhost:27017
docker-compose up --build -d
to start building the containers in the background.- Go to
localhost:8000/docs
to access the interactive Swagger UI of the API.
- Install poetry - the Python dependency management.
poetry shell
to create a virtual environment of the project.poetry install
to install dependencies.uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
to start the API service in development mode (hot reload).- Go to
localhost:8000/docs
to access the interactive Swagger UI of the API.
While developing, run
pre-commit install
before committing any changes. pre-commit runs a style check through all changed files before committing. The rules ofpre-commits
are in.pre-commit-config.yml
file.
chmod +x run_tests.sh && ./run_tests.sh
to run tests inside the container.
- Start the app on local port 8000 (refer to the build instruction above).
chmod +x run_tests.sh && ./run_tests.sh
to run tests using script.- Without script, tests can be ran with command
pytest app/tests
.
app
is the main directory containing all the source code../app/main.py
: the main start up file../run_tests.sh
: the script file to run tests.- Each of the subfolder in
./app
has aREADME.md
for more details.
The project is containerized and deployed with docker-compose on my personal Digital Ocean VM.