Skip to content

Commit 2d5a5d0

Browse files
authored
📝 Add docs about pinning versions for deployment (fastapi#1056)
1 parent d4ddf4e commit 2d5a5d0

File tree

1 file changed

+90
-6
lines changed

1 file changed

+90
-6
lines changed

docs/deployment.md

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,92 @@
1-
You can use <a href="https://www.docker.com/" class="external-link" target="_blank">**Docker**</a> for deployment. It has several advantages like security, replicability, development simplicity, etc.
1+
Deploying a **FastAPI** application is relatively easy.
2+
3+
There are several ways to do it depending on your specific use case and the tools that you use.
4+
5+
You will see more about some of the ways to do it in the next sections.
6+
7+
## FastAPI versions
8+
9+
**FastAPI** is already being used in production in many applications and systems. And the test coverage is kept at 100%. But its development is still moving quickly.
10+
11+
New features are added frequently, bugs are fixed regularly, and the code is still continuously improving.
12+
13+
That's why the current versions are still `0.x.x`, this reflects that each version could potentially have breaking changes. This follows the <a href="https://semver.org/" class="external-link" target="_blank">Semantic Versioning</a> conventions.
14+
15+
You can create production applications with **FastAPI** right now (and you have probably been doing it for some time), you just have to make sure that you use a version that works correctly with the rest of your code.
16+
17+
The first thing you should do is to "pin" the version of FastAPI you are using to the specific latest version that you know works correctly for your application.
18+
19+
For example, let's say you are using version `0.45.0` in your app.
20+
21+
If you use a `requirements.txt` file you could specify the version with:
22+
23+
```txt
24+
fastapi==0.45.0
25+
```
26+
27+
that would mean that you would use exactly the version `0.45.0`.
28+
29+
Or you could also pin it with:
30+
31+
```txt
32+
fastapi>=0.45.0,<0.46.0
33+
```
34+
35+
that would mean that you would use the versions `0.45.0` or above, but less than `0.46.0`, for example, a version `0.45.2` would still be accepted.
36+
37+
If you use any other tool to manage your installations, like Poetry, Pipenv, or others, they all have a way that you can use to define specific versions for your packages.
38+
39+
### About versions
40+
41+
Following the Semantic Versioning conventions, any version below `1.0.0` could potentially add breaking changes.
42+
43+
FastAPI also follows the convention that any "PATCH" version change is for bug fixes and non-breaking changes.
44+
45+
!!! tip
46+
The "PATCH" is the last number, for example, in `0.2.3`, the PATCH version is `3`.
47+
48+
So, you should be able to pin to a version like:
49+
50+
```txt
51+
fastapi>=0.45.0,<0.46.0
52+
```
53+
54+
Breaking changes and new features are added in "MINOR" versions.
55+
56+
!!! tip
57+
The "MINOR" is the number in the middle, for example, in `0.2.3`, the MINOR version is `2`.
58+
59+
### Upgrading the FastAPI versions
60+
61+
You should add tests for your app.
62+
63+
With **FastAPI** it's very easy (thanks to Starlette), check the docs: [Testing](tutorial/testing.md){.internal-link target=_blank}
64+
65+
After you have tests, then you can upgrade the **FastAPI** version to a more recent one, and make sure that all your code is working correctly by running your tests.
66+
67+
If everything is working, or after you make the necessary changes, and all your tests are passing, then you can pin your `fastapi` to that new recent version.
68+
69+
### About Starlette
70+
71+
You shouldn't pin the version of `starlette`.
72+
73+
Different versions of **FastAPI** will use a specific newer version of Starlette.
74+
75+
So, you can just let **FastAPI** use the correct Starlette version.
76+
77+
### About Pydantic
78+
79+
Pydantic includes the tests for **FastAPI** with its own tests, so new versions of Pydantic (above `1.0.0`) are always compatible with FastAPI.
80+
81+
You can pin Pydantic to any version above `1.0.0` that works for you and below `2.0.0`.
82+
83+
For example:
84+
85+
```txt
86+
pydantic>=1.2.0,<2.0.0
87+
```
88+
89+
## Docker
290

391
In this section you'll see instructions and links to guides to know how to:
492

@@ -7,11 +95,7 @@ In this section you'll see instructions and links to guides to know how to:
795
* Set up a Docker Swarm mode cluster with automatic HTTPS, even on a simple $5 USD/month server. In about **20 min**.
896
* Generate and deploy a full **FastAPI** application, using your Docker Swarm cluster, with HTTPS, etc. In about **10 min**.
997

10-
---
11-
12-
You can also easily use **FastAPI** in a standard server directly too (without Docker).
13-
14-
## Docker
98+
You can use <a href="https://www.docker.com/" class="external-link" target="_blank">**Docker**</a> for deployment. It has several advantages like security, replicability, development simplicity, etc.
1599

16100
If you are using Docker, you can use the official Docker image:
17101

0 commit comments

Comments
 (0)