You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/integrations/fastapi-integration.txt
+55-40Lines changed: 55 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -18,75 +18,85 @@ FastAPI Integration Tutorial
18
18
:description: Learn how to create an app to connect to MongoDB deployment by using the PyMongo driver.
19
19
:keywords: quick start, tutorial, basics
20
20
21
-
`FastAPI <https://fastapi.tiangolo.com/>`__ is a modern, high-performance, easy-to-learn, fast-to-code, production-ready, Python 3.6+ framework for building APIs based on standard Python type hints. While it might not be as established as some other Python frameworks such as Django, it is already in production at companies such as Uber, Netflix, and Microsoft.
22
-
23
-
FastAPI is async, and as its name implies, it is super fast; so, MongoDB is the perfect accompaniment. In this quick start, we will create a CRUD (Create, Read, Update, Delete) app showing how you can integrate MongoDB with your FastAPI projects.
21
+
`FastAPI <https://fastapi.tiangolo.com/>`__ is a high-performance,
22
+
production-ready asynchronous Python framework for building APIs based on
23
+
standard Python type hints. In this tutorial, we will create a CRUD application
24
+
showing how you can integrate MongoDB with your FastAPI projects.
24
25
25
26
Prerequisites
26
27
-------------
27
28
28
-
- Python 3.9.0
29
-
- A MongoDB Atlas cluster. Follow the "`Get Started with Atlas <https://docs.atlas.mongodb.com/getting-started/>`__" guide to create your account and MongoDB cluster. Keep a note of your username, password, and `connection string <https://docs.atlas.mongodb.com/tutorial/connect-to-your-cluster/#connect-to-your-atlas-cluster>`__` as you will need those later.
29
+
- Python v3.9.0 or later
30
+
- A MongoDB Atlas cluster
31
+
See the `Get Started with Atlas
32
+
<https://docs.atlas.mongodb.com/getting-started/>`__ guide to create your
33
+
account and MongoDB cluster.
30
34
31
-
Running the Example
32
-
-------------------
35
+
Set-up
36
+
------
33
37
34
-
To begin, you should `clone the example code from GitHub <https://github.com/mongodb-developer/mongodb-with-fastapi>`__.
38
+
1. Clone the example code from the `mongodb-with-fastapi repository <https://github.com/mongodb-developer/mongodb-with-fastapi>`__:
You will need to install a few dependencies: FastAPI, `Motor <https://motor.readthedocs.io/>`__, etc. I always recommend that you install all Python dependencies in a `virtualenv <https://docs.python.org/3/tutorial/venv.html>`__ for the project. Before running pip, ensure your ``virtualenv`` is active.
44
+
#. Install the required dependencies listed in the ``requirements.txt`` file:
41
45
42
-
.. code-block:: shell
46
+
.. tip:: Use a Virtual environment
43
47
44
-
cd mongodb-with-fastapi
45
-
pip install -r requirements.txt
48
+
Installing your Python dependencies in a `virtualenv
49
+
<https://docs.python.org/3/tutorial/venv.html>`__ with allow for versions
50
+
of the libraries to be install for individual projects. Before running
51
+
pip, ensure your ``virtualenv`` is active.
46
52
47
-
It may take a few moments to download and install your dependencies. This is normal, especially if you have not installed a particular package before.
53
+
.. code-block:: shell
48
54
49
-
Once you have installed the dependencies, you need to create an environment variable for your MongoDB connection string.
55
+
cd mongodb-with-fastapi
56
+
pip install -r requirements.txt
50
57
51
-
.. code-block:: shell
58
+
It may take a few moments to download and install your dependencies.
#. Create an environment variable for your MongoDB connection string:
54
61
55
-
Remember, anytime you start a new terminal session, you will need to set this environment variable again. I use `direnv <https://direnv.net/>`__ to make this process easier.
We're using the async `motor driver <https://motor.readthedocs.io/en/stable/>`__ to create our MongoDB client, and then we specify our database name ``college``.
@@ -336,7 +346,12 @@ Our final route is ``delete_student``. Again, because this is acting upon a sing
336
346
Our New FastAPI App Generator
337
347
-----------------------------
338
348
339
-
If you're excited to build something more production-ready with FastAPI, React & MongoDB, head over to the `Github repository <https://github.com/mongodb-labs/full-stack-fastapi-mongodb>`__ for our `new FastAPI app generator <https://www.mongodb.com/blog/post/introducing-full-stack-fast-api-app-generator-for-python-developers>`__ and start transforming your web development experience.
349
+
If you're excited to build something more production-ready with FastAPI, React &
350
+
MongoDB, head over to the `full-stack-fastapi-mongodb Github repository
351
+
<https://github.com/mongodb-labs/full-stack-fastapi-mongodb>`__ for our `new
0 commit comments