Skip to content

Example of building a Python API using FastAPI & MongoDB

License

Notifications You must be signed in to change notification settings

delineateio/python-mongodb-api

Repository files navigation

PRs Welcome Contributors Forks Stargazers Issues MIT License


delineate.io

delineate.io

portray or describe (something) precisely.

Python FastAPI & MongoDB API

A repo to demonstrate the building of a more advanced API using more FastAPI features and some other useful packages.
Explore the docs »

Report Bug · Request Feature

Table of Contents

About The Project

This repo shows a relatively realistic API implementation for a simple CRUD like API, that stores it's data in MongoDB. It demonstrates a some more isoterical features of FastAPI. In addition some 3rd party packages have been used to provide functionality that would likely be required in a production solution, specifically:

  • tenacity is used to provide retry decorators for certain functions/methods
  • dependency-injector was used for dependency injection to reduce coupling

Built With

Further logos can be inserted to highlight the specific technologies used to create the solution from here.

Syntax Description
Python Implementation of the API using FastAPI
MongoDB Data storage of the entities created through the API
Postman Collection of API tests to ensure the API is working as expected
pre-commit Pre-commit git hooks that perform checks before pushes
GitHub Source control management platform
Docker Provide the required local environment in a container

Getting Started

This repo follows the principle of minimal manual setup of the local development environment. If using VSCode and devcontainers a full local environment is provisioned. If running on a different IDE then taskfile can be used to simplify the local setup by using task init. This command will intsall pip dependencies, stand up the docker services and installs pre-commit. High level the following local software is required:

  • Taskfile
  • Python >= 3.10
  • Docker & Docker Compose
  • Httpie

Usage

Infrastructure

A boilerplate docker-compose file is provided that can be used to manage local environment services. The stack can be found at ops/local/stack.yaml. For convience some simple commands have been provided.

# stands up the local services
task local:up

# tears down the local services
task local:down

API

Once the [MongoDB] instance is running in Docker it is possible to run the API. In VSCode A debugging lunch has been provided for VSCode called customers-api. When the API is running then it's health can be tested using http :8000/healthz.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

If you would like to contribute to any delineate.io OSS projects please read:

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

About

Example of building a Python API using FastAPI & MongoDB

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •