https://github.com/mongodb-developer/mongodb-with-fastapi
Example of using MongoDB with FastAPI
https://github.com/mongodb-developer/mongodb-with-fastapi
Last synced: 3 months ago
JSON representation
Example of using MongoDB with FastAPI
- Host: GitHub
- URL: https://github.com/mongodb-developer/mongodb-with-fastapi
- Owner: mongodb-developer
- Created: 2020-12-04T08:58:06.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-11T11:09:16.000Z (over 1 year ago)
- Last Synced: 2025-03-29T13:04:21.520Z (3 months ago)
- Language: Python
- Size: 12.7 KB
- Stars: 340
- Watchers: 10
- Forks: 163
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MongoDB with FastAPI
This is a small sample project demonstrating how to build an API with [MongoDB](https://developer.mongodb.com/) and [FastAPI](https://fastapi.tiangolo.com/).
It was written to accompany a [blog post](https://developer.mongodb.com/quickstart/python-quickstart-fastapi/) - you should go read it!If you want to fastrack your project even further, check out the [MongoDB FastAPI app generator](https://github.com/mongodb-labs/full-stack-fastapi-mongodb) and eliminate much of the boilerplate of getting started.
## TL;DR
If you really don't want to read the [blog post](https://developer.mongodb.com/quickstart/python-quickstart-fastapi/) and want to get up and running,
activate your Python virtualenv, and then run the following from your terminal (edit the `MONGODB_URL` first!):```bash
# Install the requirements:
pip install -r requirements.txt# Configure the location of your MongoDB database:
export MONGODB_URL="mongodb+srv://:@/?retryWrites=true&w=majority"# Start the service:
uvicorn app:app --reload
```(Check out [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) if you need a MongoDB database.)
Now you can load http://localhost:8000/docs in your browser ... but there won't be much to see until you've inserted some data.
If you have any questions or suggestions, check out the [MongoDB Community Forums](https://developer.mongodb.com/community/forums/)!