43 lines
905 B
Markdown
43 lines
905 B
Markdown
|
|
## Set up virtual environnement
|
|
|
|
At the root of your repository, first set up a python virtual environnement.
|
|
|
|
`$ python -m venv .venv`
|
|
|
|
This will be useful to keep track of the dependencies
|
|
|
|
[source](https://docs.python.org/3/library/venv.html)
|
|
|
|
Activate it
|
|
`$ source .venv/bin/activate`
|
|
|
|
now you should see `(.venv) ~/Code/fastapi-corbia-telegram$ `
|
|
|
|
`pip install --upgrade pip`
|
|
|
|
`(.venv) ~/Code/fastapi-corbia-telegram$ pip install fastapi[all] uvicorn`
|
|
|
|
To save the dependency list, you can run the pip freeze command and send the output to a requirement.txt
|
|
|
|
`(.venv) ~/Code/fastapi-corbia-telegram$ pip freeze > requirements.txt`
|
|
|
|
Later on, when you deploy your application on a server, you will be able to run
|
|
|
|
`(.venv) pip install -r requirements.txt`
|
|
|
|
## Hello world
|
|
|
|
```python
|
|
from fastapi import FastAPI
|
|
|
|
app = FastAPI()
|
|
|
|
@app.get("/")
|
|
def read_root():
|
|
return {"Hello": "World"}
|
|
|
|
```
|
|
|
|
|