https://github.com/shahaf-f-s/auto-fastapi
A pythonic functional way to construct FastAPI applications be declaring endpoints in separation of their functional definition, enabeling to separate, replicate, and reuse functions in different APIs at the same time, and also run multiple of them.
https://github.com/shahaf-f-s/auto-fastapi
fastapi fastapi-extension http server uvicorn
Last synced: about 1 month ago
JSON representation
A pythonic functional way to construct FastAPI applications be declaring endpoints in separation of their functional definition, enabeling to separate, replicate, and reuse functions in different APIs at the same time, and also run multiple of them.
- Host: GitHub
- URL: https://github.com/shahaf-f-s/auto-fastapi
- Owner: Shahaf-F-S
- Created: 2024-01-12T18:40:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-07T10:33:39.000Z (about 2 years ago)
- Last Synced: 2026-03-16T12:56:18.102Z (3 months ago)
- Topics: fastapi, fastapi-extension, http, server, uvicorn
- Language: Python
- Homepage:
- Size: 35.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# auto-fastapi
> A pythonic functional way to construct FastAPI applications be declaring endpoints in separation of their functional definition, enabeling to separate, replicate, and reuse functions in different APIs at the same time, and also run multiple of them.
## Installation
```
pip install autl-fastapi
```
## example
```python
from fastapi import FastAPI
from auto_fastapi import Method, AutoFastAPI, Builder, Server, Config
def startup() -> None:
print("startup")
def login(username: str, password: str) -> dict[str, str | dict[str, str]]:
return {
"response": "success",
"request": dict(username=username, password=password)
}
app = FastAPI()
auto = AutoFastAPI(app)
auto.push((startup, Builder.event("startup")))
auto.push((login, Builder.endpoint("/login", [Method.GET])))
server = Server(Config(app, host="127.0.0.1", port=5555))
server.run()
```
to stop the server
```python
server.exit()
```
to run again
```python
server.run()
```