diff --git a/.github/actions/people/app/main.py b/.github/actions/people/app/main.py index a4d3af1fd..2847ccae4 100644 --- a/.github/actions/people/app/main.py +++ b/.github/actions/people/app/main.py @@ -375,7 +375,7 @@ def get_contributors(settings: Settings): return contributors, commentors, reviewers, authors -def get_sponsors(settings: Settings): +def get_individual_sponsors(settings: Settings, max_individual_sponsor: int = 5): nodes: List[SponsorshipAsMaintainerNode] = [] edges = get_graphql_sponsor_edges(settings=settings) @@ -387,6 +387,8 @@ def get_sponsors(settings: Settings): entities: Dict[str, SponsorEntity] = {} for node in nodes: + if node.tier.monthlyPriceInDollars > max_individual_sponsor: + continue entities[node.sponsorEntity.login] = node.sponsorEntity return entities @@ -473,7 +475,7 @@ if __name__ == "__main__": skip_users=skip_users, ) - sponsors_by_login = get_sponsors(settings=settings) + sponsors_by_login = get_individual_sponsors(settings=settings) sponsors = [] for login, sponsor in sponsors_by_login.items(): sponsors.append( diff --git a/README.md b/README.md index d0b73f9fc..67ddcd87b 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,16 @@ The key features are: * estimation based on tests on an internal development team, building production applications. +## Gold Sponsors + + + + + + + +Other sponsors + ## Opinions "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/en/data/sponsors.yml b/docs/en/data/sponsors.yml new file mode 100644 index 000000000..931e62813 --- /dev/null +++ b/docs/en/data/sponsors.yml @@ -0,0 +1,8 @@ +gold: + - url: https://www.deta.sh/?ref=fastapi + title: The launchpad for all your (team's) ideas + img: /img/sponsors/deta.svg +silver: + - url: https://testdriven.io/ + title: Learn to build high-quality web apps with best practices + img: /img/sponsors/testdriven.svg diff --git a/docs/en/docs/alternatives.md b/docs/en/docs/alternatives.md index 3d9e3a55a..cec53a4e2 100644 --- a/docs/en/docs/alternatives.md +++ b/docs/en/docs/alternatives.md @@ -410,7 +410,7 @@ It is the recommended server for Starlette and **FastAPI**. You can combine it with Gunicorn, to have an asynchronous multi-process server. - Check more details in the [Deployment](deployment.md){.internal-link target=_blank} section. + Check more details in the [Deployment](deployment/index.md){.internal-link target=_blank} section. ## Benchmarks and speed diff --git a/docs/en/docs/async.md b/docs/en/docs/async.md index ac21b3eed..7c3dcfdea 100644 --- a/docs/en/docs/async.md +++ b/docs/en/docs/async.md @@ -261,7 +261,7 @@ But you can also exploit the benefits of parallelism and multiprocessing (having That, plus the simple fact that Python is the main language for **Data Science**, Machine Learning and especially Deep Learning, make FastAPI a very good match for Data Science / Machine Learning web APIs and applications (among many others). -To see how to achieve this parallelism in production see the section about [Deployment](deployment.md){.internal-link target=_blank}. +To see how to achieve this parallelism in production see the section about [Deployment](deployment/index.md){.internal-link target=_blank}. ## `async` and `await` diff --git a/docs/en/docs/deployment.md b/docs/en/docs/deployment.md deleted file mode 100644 index 5e62d1e8d..000000000 --- a/docs/en/docs/deployment.md +++ /dev/null @@ -1,396 +0,0 @@ -# Deployment - -Deploying a **FastAPI** application is relatively easy. - -There are several ways to do it depending on your specific use case and the tools that you use. - -You will see more about some of the ways to do it in the next sections. - -## FastAPI versions - -**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. - -New features are added frequently, bugs are fixed regularly, and the code is still continuously improving. - -That's why the current versions are still `0.x.x`, this reflects that each version could potentially have breaking changes. This follows the Semantic Versioning conventions. - -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. - -### Pin your `fastapi` version - -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. - -For example, let's say you are using version `0.45.0` in your app. - -If you use a `requirements.txt` file you could specify the version with: - -```txt -fastapi==0.45.0 -``` - -that would mean that you would use exactly the version `0.45.0`. - -Or you could also pin it with: - -```txt -fastapi>=0.45.0,<0.46.0 -``` - -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. - -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. - -### Available versions - -You can see the available versions (e.g. to check what is the current latest) in the [Release Notes](release-notes.md){.internal-link target=_blank}. - -### About versions - -Following the Semantic Versioning conventions, any version below `1.0.0` could potentially add breaking changes. - -FastAPI also follows the convention that any "PATCH" version change is for bug fixes and non-breaking changes. - -!!! tip - The "PATCH" is the last number, for example, in `0.2.3`, the PATCH version is `3`. - -So, you should be able to pin to a version like: - -```txt -fastapi>=0.45.0,<0.46.0 -``` - -Breaking changes and new features are added in "MINOR" versions. - -!!! tip - The "MINOR" is the number in the middle, for example, in `0.2.3`, the MINOR version is `2`. - -### Upgrading the FastAPI versions - -You should add tests for your app. - -With **FastAPI** it's very easy (thanks to Starlette), check the docs: [Testing](tutorial/testing.md){.internal-link target=_blank} - -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. - -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. - -### About Starlette - -You shouldn't pin the version of `starlette`. - -Different versions of **FastAPI** will use a specific newer version of Starlette. - -So, you can just let **FastAPI** use the correct Starlette version. - -### About Pydantic - -Pydantic includes the tests for **FastAPI** with its own tests, so new versions of Pydantic (above `1.0.0`) are always compatible with FastAPI. - -You can pin Pydantic to any version above `1.0.0` that works for you and below `2.0.0`. - -For example: - -```txt -pydantic>=1.2.0,<2.0.0 -``` - -## Docker - -In this section you'll see instructions and links to guides to know how to: - -* Make your **FastAPI** application a Docker image/container with maximum performance. In about **5 min**. -* (Optionally) understand what you, as a developer, need to know about HTTPS. -* Set up a Docker Swarm mode cluster with automatic HTTPS, even on a simple $5 USD/month server. In about **20 min**. -* Generate and deploy a full **FastAPI** application, using your Docker Swarm cluster, with HTTPS, etc. In about **10 min**. - -You can use **Docker** for deployment. It has several advantages like security, replicability, development simplicity, etc. - -If you are using Docker, you can use the official Docker image: - -### tiangolo/uvicorn-gunicorn-fastapi - -This image has an "auto-tuning" mechanism included, so that you can just add your code and get very high performance automatically. And without making sacrifices. - -But you can still change and update all the configurations with environment variables or configuration files. - -!!! tip - To see all the configurations and options, go to the Docker image page: tiangolo/uvicorn-gunicorn-fastapi. - -### Create a `Dockerfile` - -* Go to your project directory. -* Create a `Dockerfile` with: - -```Dockerfile -FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7 - -COPY ./app /app -``` - -#### Bigger Applications - -If you followed the section about creating [Bigger Applications with Multiple Files](tutorial/bigger-applications.md){.internal-link target=_blank}, your `Dockerfile` might instead look like: - -```Dockerfile -FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7 - -COPY ./app /app/app -``` - -#### Raspberry Pi and other architectures - -If you are running Docker in a Raspberry Pi (that has an ARM processor) or any other architecture, you can create a `Dockerfile` from scratch, based on a Python base image (that is multi-architecture) and use Uvicorn alone. - -In this case, your `Dockerfile` could look like: - -```Dockerfile -FROM python:3.7 - -RUN pip install fastapi uvicorn - -EXPOSE 80 - -COPY ./app /app - -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] -``` - -### Create the **FastAPI** Code - -* Create an `app` directory and enter in it. -* Create a `main.py` file with: - -```Python -from typing import Optional - -from fastapi import FastAPI - -app = FastAPI() - - -@app.get("/") -def read_root(): - return {"Hello": "World"} - - -@app.get("/items/{item_id}") -def read_item(item_id: int, q: Optional[str] = None): - return {"item_id": item_id, "q": q} -``` - -* You should now have a directory structure like: - -``` -. -├── app -│ └── main.py -└── Dockerfile -``` - -### Build the Docker image - -* Go to the project directory (in where your `Dockerfile` is, containing your `app` directory). -* Build your FastAPI image: - -
- -```console -$ docker build -t myimage . - ----> 100% -``` - -
- -### Start the Docker container - -* Run a container based on your image: - -
- -```console -$ docker run -d --name mycontainer -p 80:80 myimage -``` - -
- -Now you have an optimized FastAPI server in a Docker container. Auto-tuned for your current server (and number of CPU cores). - -### Check it - -You should be able to check it in your Docker container's URL, for example: http://192.168.99.100/items/5?q=somequery or http://127.0.0.1/items/5?q=somequery (or equivalent, using your Docker host). - -You will see something like: - -```JSON -{"item_id": 5, "q": "somequery"} -``` - -### Interactive API docs - -Now you can go to http://192.168.99.100/docs or http://127.0.0.1/docs (or equivalent, using your Docker host). - -You will see the automatic interactive API documentation (provided by Swagger UI): - -![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) - -### Alternative API docs - -And you can also go to http://192.168.99.100/redoc or http://127.0.0.1/redoc (or equivalent, using your Docker host). - -You will see the alternative automatic documentation (provided by ReDoc): - -![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) - -## HTTPS - -### About HTTPS - -It is easy to assume that HTTPS is something that is just "enabled" or not. - -But it is way more complex than that. - -!!! tip - If you are in a hurry or don't care, continue with the next section for step by step instructions to set everything up. - -To learn the basics of HTTPS, from a consumer perspective, check https://howhttps.works/. - -Now, from a developer's perspective, here are several things to have in mind while thinking about HTTPS: - -* For HTTPS, the server needs to have "certificates" generated by a third party. - * Those certificates are actually acquired from the third-party, not "generated". -* Certificates have a lifetime. - * They expire. - * And then they need to be renewed, acquired again from the third party. -* The encryption of the connection happens at the TCP level. - * That's one layer below HTTP. - * So, the certificate and encryption handling is done before HTTP. -* TCP doesn't know about "domains". Only about IP addresses. - * The information about the specific domain requested goes in the HTTP data. -* The HTTPS certificates "certify" a certain domain, but the protocol and encryption happen at the TCP level, before knowing which domain is being dealt with. -* By default, that would mean that you can only have one HTTPS certificate per IP address. - * No matter how big your server is or how small each application you have on it might be. - * There is a solution to this, however. -* There's an extension to the TLS protocol (the one handling the encryption at the TCP level, before HTTP) called SNI. - * This SNI extension allows one single server (with a single IP address) to have several HTTPS certificates and serve multiple HTTPS domains/applications. - * For this to work, a single component (program) running on the server, listening on the public IP address, must have all the HTTPS certificates in the server. -* After obtaining a secure connection, the communication protocol is still HTTP. - * The contents are encrypted, even though they are being sent with the HTTP protocol. - -It is a common practice to have one program/HTTP server running on the server (the machine, host, etc.) and managing all the HTTPS parts : sending the decrypted HTTP requests to the actual HTTP application running in the same server (the **FastAPI** application, in this case), take the HTTP response from the application, encrypt it using the appropriate certificate and sending it back to the client using HTTPS. This server is often called a TLS Termination Proxy. - -### Let's Encrypt - -Before Let's Encrypt, these HTTPS certificates were sold by trusted third-parties. - -The process to acquire one of these certificates used to be cumbersome, require quite some paperwork and the certificates were quite expensive. - -But then Let's Encrypt was created. - -It is a project from the Linux Foundation. It provides HTTPS certificates for free. In an automated way. These certificates use all the standard cryptographic security, and are short lived (about 3 months), so the security is actually better because of their reduced lifespan. - -The domains are securely verified and the certificates are generated automatically. This also allows automating the renewal of these certificates. - -The idea is to automate the acquisition and renewal of these certificates, so that you can have secure HTTPS, for free, forever. - -### Traefik - -Traefik is a high performance reverse proxy / load balancer. It can do the "TLS Termination Proxy" job (apart from other features). - -It has integration with Let's Encrypt. So, it can handle all the HTTPS parts, including certificate acquisition and renewal. - -It also has integrations with Docker. So, you can declare your domains in each application configurations and have it read those configurations, generate the HTTPS certificates and serve HTTPS to your application automatically, without requiring any change in its configuration. - ---- - -With this information and tools, continue with the next section to combine everything. - -## Docker Swarm mode cluster with Traefik and HTTPS - -You can have a Docker Swarm mode cluster set up in minutes (about 20 min) with a main Traefik handling HTTPS (including certificate acquisition and renewal). - -By using Docker Swarm mode, you can start with a "cluster" of a single machine (it can even be a $5 USD / month server) and then you can grow as much as you need adding more servers. - -To set up a Docker Swarm Mode cluster with Traefik and HTTPS handling, follow this guide: - -### Docker Swarm Mode and Traefik for an HTTPS cluster - -### Deploy a FastAPI application - -The easiest way to set everything up, would be using the [**FastAPI** Project Generators](project-generation.md){.internal-link target=_blank}. - -It is designed to be integrated with this Docker Swarm cluster with Traefik and HTTPS described above. - -You can generate a project in about 2 min. - -The generated project has instructions to deploy it, doing it takes another 2 min. - -## Alternatively, deploy **FastAPI** without Docker - -You can deploy **FastAPI** directly without Docker too. - -You just need to install an ASGI compatible server like: - -=== "Uvicorn" - - * Uvicorn, a lightning-fast ASGI server, built on uvloop and httptools. - -
- - ```console - $ pip install uvicorn - - ---> 100% - ``` - -
- -=== "Hypercorn" - - * Hypercorn, an ASGI server also compatible with HTTP/2. - -
- - ```console - $ pip install hypercorn - - ---> 100% - ``` - -
- - ...or any other ASGI server. - -And run your application the same way you have done in the tutorials, but without the `--reload` option, e.g.: - -=== "Uvicorn" - -
- - ```console - $ uvicorn main:app --host 0.0.0.0 --port 80 - - INFO: Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit) - ``` - -
- -=== "Hypercorn" - -
- - ```console - $ hypercorn main:app --bind 0.0.0.0:80 - - Running on 0.0.0.0:8080 over http (CTRL + C to quit) - ``` - -
- -You might want to set up some tooling to make sure it is restarted automatically if it stops. - -You might also want to install Gunicorn and use it as a manager for Uvicorn, or use Hypercorn with multiple workers. - -Making sure to fine-tune the number of workers, etc. - -But if you are doing all that, you might just use the Docker image that does it automatically. diff --git a/docs/en/docs/deployment/deta.md b/docs/en/docs/deployment/deta.md new file mode 100644 index 000000000..ae7a00d3d --- /dev/null +++ b/docs/en/docs/deployment/deta.md @@ -0,0 +1,240 @@ +# Deploy on Deta + +In this section you will learn see how to easily deploy a **FastAPI** application on Deta using the free plan. 🎁 + +It will take you about **10 minutes**. + +!!! info + Deta is a **FastAPI** sponsor. 🎉 + +## A basic **FastAPI** app + +* Create a directory for your app, for example `./fastapideta/` and enter in it. + +### FastAPI code + +* Create a `main.py` file with: + +```Python +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +def read_root(): + return {"Hello": "World"} + + +@app.get("/items/{item_id}") +def read_item(item_id: int): + return {"item_id": item_id} +``` + +### Requirements + +Now, in the same directory create a file `requirements.txt` with: + +```text +fastapi +``` + +!!! tip + You don't need to install Uvicorn to deploy on Deta, although you would probably want to install it locally to test your app. + +### Directory structure + +You will now have one directory `./fastapideta/` with two files: + +``` +. +└── main.py +└── requirements.txt +``` + +## Create a free Deta account + +Now create a free account on Deta, you just need an email and password. + +You don't even need a credit card. + +## Install the CLI + +Once you have your account, install the Deta CLI: + +=== "Linux, macOS" + +
+ + ```console + $ curl -fsSL https://get.deta.dev/cli.sh | sh + ``` + +
+ +=== "Windows PowerShell" + +
+ + ```console + $ iwr https://get.deta.dev/cli.ps1 -useb | iex + ``` + +
+ +After installing it, open a new terminal so that the installed CLI is detected. + +In a new terminal, confirm that it was correctly installed with: + +
+ +```console +$ deta --help + +Deta command line interface for managing deta micros. +Complete documentation available at https://docs.deta.sh + +Usage: + deta [flags] + deta [command] + +Available Commands: + auth Change auth settings for a deta micro + +... +``` + +
+ +!!! tip + If you have problems installing the CLI, check the official Deta docs. + +## Login with the CLI + +Now login to Deta from the CLI with: + +
+ +```console +$ deta login + +Please, log in from the web page. Waiting.. +Logged in successfully. +``` + +
+ +This will open a web browser and authenticate automatically. + +## Deploy with Deta + +Next, deploy your application with the Deta CLI: + +
+ +```console +$ deta new + +Successfully created a new micro + +// Notice the "endpoint" 🔍 + +{ + "name": "fastapideta", + "runtime": "python3.7", + "endpoint": "https://qltnci.deta.dev", + "visor": "enabled", + "http_auth": "enabled" +} + +Adding dependencies... + + +---> 100% + + +Successfully installed fastapi-0.61.1 pydantic-1.7.2 starlette-0.13.6 +``` + +
+ +You will see a JSON message similar to: + +```JSON hl_lines="4" +{ + "name": "fastapideta", + "runtime": "python3.7", + "endpoint": "https://qltnci.deta.dev", + "visor": "enabled", + "http_auth": "enabled" +} +``` + +!!! tip + Your deployment will have a different `"endpoint"` URL. + +## Check it + +Now open your browser in your `endpoint` URL. In the example above it was `https://qltnci.deta.dev`, but yours will be different. + +You will see the JSON response from your FastAPI app: + +```JSON +{ + "Hello": "World" +} +``` + +And now go to the `/docs` for your API, in the example above it would be `https://qltnci.deta.dev/docs`. + +It will show your docs like: + + + +## Enable public access + +By default, Deta will handle authentication using cookies for your account. + +But once you are ready, you can make it public with: + +
+ +```console +$ deta auth disable + +Successfully disabled http auth +``` + +
+ +Now you can share that URL with anyone and they will be able to access your API. 🚀 + +## HTTPS + +Congrats! You deployed your FastAPI app to Deta! 🎉 🍰 + +Also notice that Deta correctly handles HTTPS for you, so you don't have to take care of that and can be sure that your clients will have a secure encrypted connection. ✅ 🔒 + +## Check the Visor + +From your docs UI (they will be in a URL like `https://qltnci.deta.dev/docs`) send a request to your *path operation* `/items/{item_id}`. + +For example with ID `5`. + +Now go to https://web.deta.sh. + +You will see there's a section to the left called "Micros" with each of your apps. + +You will see a tab with "Details", and also a tab "Visor", go to the tab "Visor". + +In there you can inspect the recent requests sent to your app. + +You can also edit them and re-play them. + + + +## Learn more + +At some point you will probably want to store some data for your app in a way that persists through time. For that you can use Deta Base, it also has a generous **free tier**. + +You can also read more in the Deta Docs. diff --git a/docs/en/docs/deployment/docker.md b/docs/en/docs/deployment/docker.md new file mode 100644 index 000000000..e32a2969d --- /dev/null +++ b/docs/en/docs/deployment/docker.md @@ -0,0 +1,179 @@ +# Deploy with Docker + +In this section you'll see instructions and links to guides to know how to: + +* Make your **FastAPI** application a Docker image/container with maximum performance. In about **5 min**. +* (Optionally) understand what you, as a developer, need to know about HTTPS. +* Set up a Docker Swarm mode cluster with automatic HTTPS, even on a simple $5 USD/month server. In about **20 min**. +* Generate and deploy a full **FastAPI** application, using your Docker Swarm cluster, with HTTPS, etc. In about **10 min**. + +You can use **Docker** for deployment. It has several advantages like security, replicability, development simplicity, etc. + +If you are using Docker, you can use the official Docker image: + +## tiangolo/uvicorn-gunicorn-fastapi + +This image has an "auto-tuning" mechanism included, so that you can just add your code and get very high performance automatically. And without making sacrifices. + +But you can still change and update all the configurations with environment variables or configuration files. + +!!! tip + To see all the configurations and options, go to the Docker image page: tiangolo/uvicorn-gunicorn-fastapi. + +## Create a `Dockerfile` + +* Go to your project directory. +* Create a `Dockerfile` with: + +```Dockerfile +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7 + +COPY ./app /app +``` + +### Bigger Applications + +If you followed the section about creating [Bigger Applications with Multiple Files](../tutorial/bigger-applications.md){.internal-link target=_blank}, your `Dockerfile` might instead look like: + +```Dockerfile +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7 + +COPY ./app /app/app +``` + +### Raspberry Pi and other architectures + +If you are running Docker in a Raspberry Pi (that has an ARM processor) or any other architecture, you can create a `Dockerfile` from scratch, based on a Python base image (that is multi-architecture) and use Uvicorn alone. + +In this case, your `Dockerfile` could look like: + +```Dockerfile +FROM python:3.7 + +RUN pip install fastapi uvicorn + +EXPOSE 80 + +COPY ./app /app + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] +``` + +## Create the **FastAPI** Code + +* Create an `app` directory and enter in it. +* Create a `main.py` file with: + +```Python +from typing import Optional + +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +def read_root(): + return {"Hello": "World"} + + +@app.get("/items/{item_id}") +def read_item(item_id: int, q: Optional[str] = None): + return {"item_id": item_id, "q": q} +``` + +* You should now have a directory structure like: + +``` +. +├── app +│ └── main.py +└── Dockerfile +``` + +## Build the Docker image + +* Go to the project directory (in where your `Dockerfile` is, containing your `app` directory). +* Build your FastAPI image: + +
+ +```console +$ docker build -t myimage . + +---> 100% +``` + +
+ +## Start the Docker container + +* Run a container based on your image: + +
+ +```console +$ docker run -d --name mycontainer -p 80:80 myimage +``` + +
+ +Now you have an optimized FastAPI server in a Docker container. Auto-tuned for your current server (and number of CPU cores). + +## Check it + +You should be able to check it in your Docker container's URL, for example: http://192.168.99.100/items/5?q=somequery or http://127.0.0.1/items/5?q=somequery (or equivalent, using your Docker host). + +You will see something like: + +```JSON +{"item_id": 5, "q": "somequery"} +``` + +## Interactive API docs + +Now you can go to http://192.168.99.100/docs or http://127.0.0.1/docs (or equivalent, using your Docker host). + +You will see the automatic interactive API documentation (provided by Swagger UI): + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) + +## Alternative API docs + +And you can also go to http://192.168.99.100/redoc or http://127.0.0.1/redoc (or equivalent, using your Docker host). + +You will see the alternative automatic documentation (provided by ReDoc): + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) + +## Traefik + +Traefik is a high performance reverse proxy / load balancer. It can do the "TLS Termination Proxy" job (apart from other features). + +It has integration with Let's Encrypt. So, it can handle all the HTTPS parts, including certificate acquisition and renewal. + +It also has integrations with Docker. So, you can declare your domains in each application configurations and have it read those configurations, generate the HTTPS certificates and serve HTTPS to your application automatically, without requiring any change in its configuration. + +--- + +With this information and tools, continue with the next section to combine everything. + +## Docker Swarm mode cluster with Traefik and HTTPS + +You can have a Docker Swarm mode cluster set up in minutes (about 20 min) with a main Traefik handling HTTPS (including certificate acquisition and renewal). + +By using Docker Swarm mode, you can start with a "cluster" of a single machine (it can even be a $5 USD / month server) and then you can grow as much as you need adding more servers. + +To set up a Docker Swarm Mode cluster with Traefik and HTTPS handling, follow this guide: + +### Docker Swarm Mode and Traefik for an HTTPS cluster + +### Deploy a FastAPI application + +The easiest way to set everything up, would be using the [**FastAPI** Project Generators](../project-generation.md){.internal-link target=_blank}. + +It is designed to be integrated with this Docker Swarm cluster with Traefik and HTTPS described above. + +You can generate a project in about 2 min. + +The generated project has instructions to deploy it, doing it takes another 2 min. diff --git a/docs/en/docs/deployment/https.md b/docs/en/docs/deployment/https.md new file mode 100644 index 000000000..c735f1f4a --- /dev/null +++ b/docs/en/docs/deployment/https.md @@ -0,0 +1,48 @@ +# About HTTPS + +It is easy to assume that HTTPS is something that is just "enabled" or not. + +But it is way more complex than that. + +!!! tip + If you are in a hurry or don't care, continue with the next sections for step by step instructions to set everything up with different techniques. + +To learn the basics of HTTPS, from a consumer perspective, check https://howhttps.works/. + +Now, from a developer's perspective, here are several things to have in mind while thinking about HTTPS: + +* For HTTPS, the server needs to have "certificates" generated by a third party. + * Those certificates are actually acquired from the third-party, not "generated". +* Certificates have a lifetime. + * They expire. + * And then they need to be renewed, acquired again from the third party. +* The encryption of the connection happens at the TCP level. + * That's one layer below HTTP. + * So, the certificate and encryption handling is done before HTTP. +* TCP doesn't know about "domains". Only about IP addresses. + * The information about the specific domain requested goes in the HTTP data. +* The HTTPS certificates "certify" a certain domain, but the protocol and encryption happen at the TCP level, before knowing which domain is being dealt with. +* By default, that would mean that you can only have one HTTPS certificate per IP address. + * No matter how big your server is or how small each application you have on it might be. + * There is a solution to this, however. +* There's an extension to the TLS protocol (the one handling the encryption at the TCP level, before HTTP) called SNI. + * This SNI extension allows one single server (with a single IP address) to have several HTTPS certificates and serve multiple HTTPS domains/applications. + * For this to work, a single component (program) running on the server, listening on the public IP address, must have all the HTTPS certificates in the server. +* After obtaining a secure connection, the communication protocol is still HTTP. + * The contents are encrypted, even though they are being sent with the HTTP protocol. + +It is a common practice to have one program/HTTP server running on the server (the machine, host, etc.) and managing all the HTTPS parts : sending the decrypted HTTP requests to the actual HTTP application running in the same server (the **FastAPI** application, in this case), take the HTTP response from the application, encrypt it using the appropriate certificate and sending it back to the client using HTTPS. This server is often called a TLS Termination Proxy. + +## Let's Encrypt + +Before Let's Encrypt, these HTTPS certificates were sold by trusted third-parties. + +The process to acquire one of these certificates used to be cumbersome, require quite some paperwork and the certificates were quite expensive. + +But then Let's Encrypt was created. + +It is a project from the Linux Foundation. It provides HTTPS certificates for free. In an automated way. These certificates use all the standard cryptographic security, and are short lived (about 3 months), so the security is actually better because of their reduced lifespan. + +The domains are securely verified and the certificates are generated automatically. This also allows automating the renewal of these certificates. + +The idea is to automate the acquisition and renewal of these certificates, so that you can have secure HTTPS, for free, forever. diff --git a/docs/en/docs/deployment/index.md b/docs/en/docs/deployment/index.md new file mode 100644 index 000000000..d898cfefc --- /dev/null +++ b/docs/en/docs/deployment/index.md @@ -0,0 +1,7 @@ +# Deployment - Intro + +Deploying a **FastAPI** application is relatively easy. + +There are several ways to do it depending on your specific use case and the tools that you use. + +You will see more details to have in mind and some of the techniques to do it in the next sections. diff --git a/docs/en/docs/deployment/manually.md b/docs/en/docs/deployment/manually.md new file mode 100644 index 000000000..405124165 --- /dev/null +++ b/docs/en/docs/deployment/manually.md @@ -0,0 +1,69 @@ +# Deploy manually + +You can deploy **FastAPI** manually as well. + +You just need to install an ASGI compatible server like: + +=== "Uvicorn" + + * Uvicorn, a lightning-fast ASGI server, built on uvloop and httptools. + +
+ + ```console + $ pip install uvicorn + + ---> 100% + ``` + +
+ +=== "Hypercorn" + + * Hypercorn, an ASGI server also compatible with HTTP/2. + +
+ + ```console + $ pip install hypercorn + + ---> 100% + ``` + +
+ + ...or any other ASGI server. + +And run your application the same way you have done in the tutorials, but without the `--reload` option, e.g.: + +=== "Uvicorn" + +
+ + ```console + $ uvicorn main:app --host 0.0.0.0 --port 80 + + INFO: Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit) + ``` + +
+ +=== "Hypercorn" + +
+ + ```console + $ hypercorn main:app --bind 0.0.0.0:80 + + Running on 0.0.0.0:8080 over http (CTRL + C to quit) + ``` + +
+ +You might want to set up some tooling to make sure it is restarted automatically if it stops. + +You might also want to install Gunicorn and use it as a manager for Uvicorn, or use Hypercorn with multiple workers. + +Making sure to fine-tune the number of workers, etc. + +But if you are doing all that, you might just use the Docker image that does it automatically. diff --git a/docs/en/docs/deployment/versions.md b/docs/en/docs/deployment/versions.md new file mode 100644 index 000000000..4be9385dd --- /dev/null +++ b/docs/en/docs/deployment/versions.md @@ -0,0 +1,87 @@ +# About FastAPI versions + +**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. + +New features are added frequently, bugs are fixed regularly, and the code is still continuously improving. + +That's why the current versions are still `0.x.x`, this reflects that each version could potentially have breaking changes. This follows the Semantic Versioning conventions. + +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. + +## Pin your `fastapi` version + +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. + +For example, let's say you are using version `0.45.0` in your app. + +If you use a `requirements.txt` file you could specify the version with: + +```txt +fastapi==0.45.0 +``` + +that would mean that you would use exactly the version `0.45.0`. + +Or you could also pin it with: + +```txt +fastapi>=0.45.0,<0.46.0 +``` + +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. + +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. + +## Available versions + +You can see the available versions (e.g. to check what is the current latest) in the [Release Notes](../release-notes.md){.internal-link target=_blank}. + +## About versions + +Following the Semantic Versioning conventions, any version below `1.0.0` could potentially add breaking changes. + +FastAPI also follows the convention that any "PATCH" version change is for bug fixes and non-breaking changes. + +!!! tip + The "PATCH" is the last number, for example, in `0.2.3`, the PATCH version is `3`. + +So, you should be able to pin to a version like: + +```txt +fastapi>=0.45.0,<0.46.0 +``` + +Breaking changes and new features are added in "MINOR" versions. + +!!! tip + The "MINOR" is the number in the middle, for example, in `0.2.3`, the MINOR version is `2`. + +## Upgrading the FastAPI versions + +You should add tests for your app. + +With **FastAPI** it's very easy (thanks to Starlette), check the docs: [Testing](../tutorial/testing.md){.internal-link target=_blank} + +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. + +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. + +## About Starlette + +You shouldn't pin the version of `starlette`. + +Different versions of **FastAPI** will use a specific newer version of Starlette. + +So, you can just let **FastAPI** use the correct Starlette version. + +## About Pydantic + +Pydantic includes the tests for **FastAPI** with its own tests, so new versions of Pydantic (above `1.0.0`) are always compatible with FastAPI. + +You can pin Pydantic to any version above `1.0.0` that works for you and below `2.0.0`. + +For example: + +```txt +pydantic>=1.2.0,<2.0.0 +``` diff --git a/docs/en/docs/fastapi-people.md b/docs/en/docs/fastapi-people.md index 80b225efd..42148c1f5 100644 --- a/docs/en/docs/fastapi-people.md +++ b/docs/en/docs/fastapi-people.md @@ -112,7 +112,25 @@ The **Top Reviewers** 🕵️ have reviewed the most Pull Requests from others, These are the **Sponsors**. 😎 -They are supporting my work with **FastAPI** (and others) through GitHub Sponsors. +They are supporting my work with **FastAPI** (and others), mainly through GitHub Sponsors. + +### Gold Sponsors + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + +### Silver Sponsors + +{% if sponsors %} +{% for sponsor in sponsors.silver -%} + +{% endfor %} +{% endif %} + +### Individual Sponsors {% if people %}
@@ -126,10 +144,12 @@ They are supporting my work with **FastAPI** (and others) through source code here. +Here I'm also highlighting contributions from sponsors. + I also reserve the right to update the algorithm, sections, thresholds, etc (just in case 🤷). diff --git a/docs/en/docs/img/deployment/deta/image01.png b/docs/en/docs/img/deployment/deta/image01.png new file mode 100644 index 000000000..f2e058b58 Binary files /dev/null and b/docs/en/docs/img/deployment/deta/image01.png differ diff --git a/docs/en/docs/img/deployment/deta/image02.png b/docs/en/docs/img/deployment/deta/image02.png new file mode 100644 index 000000000..897ec41fb Binary files /dev/null and b/docs/en/docs/img/deployment/deta/image02.png differ diff --git a/docs/en/docs/img/sponsors/deta.svg b/docs/en/docs/img/sponsors/deta.svg new file mode 100644 index 000000000..c2b77a867 --- /dev/null +++ b/docs/en/docs/img/sponsors/deta.svg @@ -0,0 +1,99 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + Deploy your FastAPI app for free + + + + + + + + diff --git a/docs/en/docs/img/sponsors/testdriven.svg b/docs/en/docs/img/sponsors/testdriven.svg new file mode 100644 index 000000000..9ed2dc72e --- /dev/null +++ b/docs/en/docs/img/sponsors/testdriven.svg @@ -0,0 +1,235 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Learn Test-Driven Development with FastAPI + + diff --git a/docs/en/docs/index.md b/docs/en/docs/index.md index d0b73f9fc..cef2d8e05 100644 --- a/docs/en/docs/index.md +++ b/docs/en/docs/index.md @@ -43,6 +43,20 @@ The key features are: * estimation based on tests on an internal development team, building production applications. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## Opinions "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index 6fa7dc664..abd0d54bb 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -123,7 +123,13 @@ nav: - advanced/openapi-callbacks.md - advanced/wsgi.md - async.md -- deployment.md +- Deployment: + - deployment/index.md + - deployment/versions.md + - deployment/https.md + - deployment/deta.md + - deployment/docker.md + - deployment/manually.md - project-generation.md - alternatives.md - history-design-future.md diff --git a/docs/es/docs/async.md b/docs/es/docs/async.md index c1d714b28..6246a3527 100644 --- a/docs/es/docs/async.md +++ b/docs/es/docs/async.md @@ -261,7 +261,7 @@ Pero también puedes aprovechar los beneficios del paralelismo y el multiprocesa Eso, más el simple hecho de que Python es el lenguaje principal para **Data Science**, Machine Learning y especialmente Deep Learning, hacen de FastAPI una muy buena combinación para las API y aplicaciones web de Data Science / Machine Learning (entre muchas otras). -Para ver cómo lograr este paralelismo en producción, consulta la sección sobre [Despliegue](deployment.md){.internal-link target=_blank}. +Para ver cómo lograr este paralelismo en producción, consulta la sección sobre [Despliegue](deployment/index.md){.internal-link target=_blank}. ## `async` y `await` diff --git a/docs/es/docs/index.md b/docs/es/docs/index.md index 30e5b1d92..77053bdbd 100644 --- a/docs/es/docs/index.md +++ b/docs/es/docs/index.md @@ -42,6 +42,20 @@ Sus características principales son: * Esta estimación está basada en pruebas con un equipo de desarrollo interno contruyendo aplicaciones listas para producción. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Otros sponsors + ## Opiniones "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/fr/docs/index.md b/docs/fr/docs/index.md index 5fb52cc3c..7013e33c1 100644 --- a/docs/fr/docs/index.md +++ b/docs/fr/docs/index.md @@ -47,6 +47,20 @@ The key features are: * estimation based on tests on an internal development team, building production applications. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## Opinions "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/it/docs/index.md b/docs/it/docs/index.md index 687cc7c2b..16ba91418 100644 --- a/docs/it/docs/index.md +++ b/docs/it/docs/index.md @@ -47,6 +47,20 @@ The key features are: * estimation based on tests on an internal development team, building production applications. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## Opinions "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/ja/docs/alternatives.md b/docs/ja/docs/alternatives.md index 57bf46118..27e3c8846 100644 --- a/docs/ja/docs/alternatives.md +++ b/docs/ja/docs/alternatives.md @@ -408,7 +408,7 @@ Starletteや**FastAPI**のサーバーとして推奨されています。 Gunicornと組み合わせることで、非同期でマルチプロセスなサーバーを持つことがきます。 - 詳細は[デプロイ](deployment.md){.internal-link target=_blank}の項目で確認してください。 + 詳細は[デプロイ](deployment/index.md){.internal-link target=_blank}の項目で確認してください。 ## ベンチマーク と スピード diff --git a/docs/ja/docs/index.md b/docs/ja/docs/index.md index 9fdce0ef2..72745e1ce 100644 --- a/docs/ja/docs/index.md +++ b/docs/ja/docs/index.md @@ -43,6 +43,20 @@ FastAPI は、Pythonの標準である型ヒントに基づいてPython 3.6 以 \* 本番アプリケーションを構築している開発チームのテストによる見積もり。 +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## 評価 "_[...] 最近 **FastAPI** を使っています。 [...] 実際に私のチームの全ての **Microsoft の機械学習サービス** で使用する予定です。 そのうちのいくつかのコアな**Windows**製品と**Office**製品に統合されつつあります。_" diff --git a/docs/ko/docs/index.md b/docs/ko/docs/index.md index 8db98885d..3f03a337f 100644 --- a/docs/ko/docs/index.md +++ b/docs/ko/docs/index.md @@ -47,6 +47,20 @@ The key features are: * estimation based on tests on an internal development team, building production applications. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## Opinions "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/pt/docs/alternatives.md b/docs/pt/docs/alternatives.md index 384eb0802..1269fe66d 100644 --- a/docs/pt/docs/alternatives.md +++ b/docs/pt/docs/alternatives.md @@ -406,7 +406,7 @@ Ele é o servidor recomendado para Starlette e **FastAPI**. Você pode combinar ele com o Gunicorn, para ter um servidor multi-processos assíncrono. - Verifique mais detalhes na seção [Deployment](deployment.md){.internal-link target=_blank}. + Verifique mais detalhes na seção [Deployment](deployment/index.md){.internal-link target=_blank}. ## Performance e velocidade diff --git a/docs/pt/docs/index.md b/docs/pt/docs/index.md index ed87d6897..906b52444 100644 --- a/docs/pt/docs/index.md +++ b/docs/pt/docs/index.md @@ -42,6 +42,20 @@ Os recursos chave são: * estimativas baseadas em testes realizados com equipe interna de desenvolvimento, construindo aplicações em produção. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## Opiniões "*[...] Estou usando **FastAPI** muito esses dias. [...] Estou na verdade planejando utilizar ele em todos os times de **serviços _Machine Learning_ na Microsoft**. Alguns deles estão sendo integrados no _core_ do produto **Windows** e alguns produtos **Office**.*" diff --git a/docs/ru/docs/index.md b/docs/ru/docs/index.md index 03abddc1d..086eb209c 100644 --- a/docs/ru/docs/index.md +++ b/docs/ru/docs/index.md @@ -47,6 +47,20 @@ The key features are: * estimation based on tests on an internal development team, building production applications. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## Opinions "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/tr/docs/index.md b/docs/tr/docs/index.md index 8db98885d..3f03a337f 100644 --- a/docs/tr/docs/index.md +++ b/docs/tr/docs/index.md @@ -47,6 +47,20 @@ The key features are: * estimation based on tests on an internal development team, building production applications. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## Opinions "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/uk/docs/index.md b/docs/uk/docs/index.md index d236da22c..671b3cf10 100644 --- a/docs/uk/docs/index.md +++ b/docs/uk/docs/index.md @@ -47,6 +47,20 @@ The key features are: * estimation based on tests on an internal development team, building production applications. +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## Opinions "_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" diff --git a/docs/zh/docs/index.md b/docs/zh/docs/index.md index 93d9d98c4..52a45eb0c 100644 --- a/docs/zh/docs/index.md +++ b/docs/zh/docs/index.md @@ -43,6 +43,20 @@ FastAPI 是一个用于构建 API 的现代、快速(高性能)的 web 框 * 根据对某个构建线上应用的内部开发团队所进行的测试估算得出。 +## Gold Sponsors + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} + + + +Other sponsors + ## 评价 「_[...] 最近我一直在使用 **FastAPI**。[...] 实际上我正在计划将其用于我所在的**微软**团队的所有**机器学习服务**。其中一些服务正被集成进核心 **Windows** 产品和一些 **Office** 产品。_」 diff --git a/scripts/docs.py b/scripts/docs.py index 284f344f6..e11bacb64 100644 --- a/scripts/docs.py +++ b/scripts/docs.py @@ -1,4 +1,5 @@ import os +import re import shutil from http.server import HTTPServer, SimpleHTTPRequestHandler from multiprocessing import Pool @@ -11,6 +12,7 @@ import mkdocs.config import mkdocs.utils import typer import yaml +from jinja2 import Template app = typer.Typer() @@ -194,6 +196,62 @@ def build_lang( typer.secho(f"Successfully built docs for: {lang}", color=typer.colors.GREEN) +index_sponsors_template = """ +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor %} +{% endif %} +""" + + +def generate_readme_content(): + en_index = en_docs_path / "docs" / "index.md" + content = en_index.read_text("utf-8") + match_start = re.search(r"", content) + match_end = re.search(r"", content) + sponsors_data_path = en_docs_path / "data" / "sponsors.yml" + sponsors = mkdocs.utils.yaml_load(sponsors_data_path.read_text(encoding="utf-8")) + if not (match_start and match_end): + raise RuntimeError("Couldn't auto-generate sponsors section") + pre_end = match_start.end() + post_start = match_end.start() + template = Template(index_sponsors_template) + message = template.render(sponsors=sponsors) + pre_content = content[:pre_end] + post_content = content[post_start:] + new_content = pre_content + message + post_content + return new_content + + +@app.command() +def generate_readme(): + """ + Generate README.md content from main index.md + """ + typer.echo("Generating README") + readme_path = Path("README.md") + new_content = generate_readme_content() + readme_path.write_text(new_content, encoding="utf-8") + + +@app.command() +def verify_readme(): + """ + Verify README.md content from main index.md + """ + typer.echo("Verifying README") + readme_path = Path("README.md") + generated_content = generate_readme_content() + readme_content = readme_path.read_text("utf-8") + if generated_content != readme_content: + typer.secho( + "README.md outdated from the latest index.md", color=typer.colors.RED + ) + raise typer.Abort() + typer.echo("Valid README ✅") + + @app.command() def build_all(): """ @@ -202,24 +260,19 @@ def build_all(): """ site_path = Path("site").absolute() update_languages(lang=None) - en_build_path: Path = docs_path / "en" current_dir = os.getcwd() - os.chdir(en_build_path) - typer.echo(f"Building docs for: en") + os.chdir(en_docs_path) + typer.echo("Building docs for: en") mkdocs.commands.build.build(mkdocs.config.load_config(site_dir=str(site_path))) os.chdir(current_dir) - langs = [] for lang in get_lang_paths(): - if lang == en_build_path or not lang.is_dir(): + if lang == en_docs_path or not lang.is_dir(): continue langs.append(lang.name) cpu_count = os.cpu_count() or 1 with Pool(cpu_count * 2) as p: p.map(build_lang, langs) - typer.echo("Copying en index.md to README.md") - en_index = en_build_path / "docs" / "index.md" - shutil.copyfile(en_index, "README.md") def update_single_lang(lang: str): diff --git a/scripts/test.sh b/scripts/test.sh index e43f179ce..b593133d8 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -5,6 +5,6 @@ set -x bash ./scripts/lint.sh # Check README.md is up to date -diff --brief docs/en/docs/index.md README.md +python ./scripts/docs.py verify-readme export PYTHONPATH=./docs_src pytest --cov=fastapi --cov=tests --cov=docs/src --cov-report=term-missing --cov-report=xml tests ${@}