<style>
.reveal {
font-size: 24pt;
width: 100%
}
.reveal .slides {
width: 90% !important;
}
.reveal blockquote {
font-size: 24pt;
}
.reveal h1 {
text-shadow: none
}
pre code .wrapper {
font-size: 20pt;
line-height: 1.5em;
}
.reveal pre {
width: 860px
}
</style>
# FastAPI 簡介
簡伯銓 (dibery)
110.5.3
---
## What is FastAPI?
> FastAPI is a **software framework** for developing **web applications** in Python.
> Initial release: December 08, 2018
> [name=Wikipedia] [color=orange]
----
## What is FastAPI?
> FastAPI is a **modern, fast (high-performance), web framework for building APIs with Python** 3.6+ based on standard Python type hints.
> [name=FastAPI official site] [color=red]
> > ... **FastAPI** ... as [one of the fastest Python frameworks](https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7)..., only below Starlette and Uvicorn ... (used internally by FastAPI).
> [name=FastAPI performance test] [color=blue]
Some popular sites like Uber & Netflix use it.
---
## FastAPI is very similar to Flask!
- With `asyc` ability
- With type check
- With auto doc generation
- Without front-end features & server
- Making it really an **API**
$\Rightarrow$ FastAPI $\approx$ Flask $-$ front-end $-$ server
$+$ type check $+$ async call $+$ doc gen
---
## How to install?
Using `pip`:
```bash=
pip install fastapi uvicorn
```
`uvicron` is a python web server that supports asyncronous calls.
---
## A quick example
```python=
import uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def home(name: str):
return {"message": f"Hello! {name}"}
if __name__ == "__main__":
uvicorn.run(app, host='127.0.0.1', port=8000)
```
----
## View the result
Open `localhost/?name=AnyNameHere` in browser

---
## The doc
The API doc can be viewed at `localhost/docs`

----
## The doc
or `localhost/redocs`

---
## END
{"metaMigratedAt":"2023-06-15T23:40:25.979Z","metaMigratedFrom":"YAML","title":"FastAPI","breaks":true,"description":"110/5/3","slideOptions":"{\"theme\":\"moon\",\"transition\":\"fades\",\"transitionSpeed\":\"fast\",\"controls\":true,\"slideNumber\":true,\"history\":false,\"keyboard\":true,\"overview\":true,\"mouseWheel\":false}","contributors":"[{\"id\":\"c8aff601-5b6d-4425-9614-6132a22b8f27\",\"add\":5345,\"del\":2915}]"}