Fastapi-utilities

Latest version: v0.2.0

Safety actively analyzes 623343 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

0.2.0

✨ Introduction of `cli` tool
Use our `cli` tool to get a fastapi skeleton built for you to directly get you started with coding.

How to use
- Using `poetry`: `poetry run cli init`
- Using `pip`: `python3 -m cli init`

0.1.3.1

🚨Support for `python3.12`

0.1.3

* **Cached Sessions**: Now use cached sessions along with context manager instead of `get_db`.


from fastapi import FastAPI
from .db import Base, engine
from fastapi_utilities import FastAPISessionMaker, repeat_every
from .models import User
import random

app = FastAPI()
Base.metadata.create_all(bind=engine)

session_maker = FastAPISessionMaker("sqlite:///db.sqlite3")


app.on_event("startup")
repeat_every(seconds=5, raise_exceptions=True)
async def startup():
print("Starting up...")
with session_maker.context_session() as session:
x = User(id=random.randint(0, 10000))
session.add(x)
print("Startup complete!")

0.1.2

* **Timer Middleware**: Add a middleware to the FastAPI app that logs the time taken to process a request. Optionally, also logs the average response time.The average response time is reset after every (reset_after)100,000 requests.




import asyncio
from fastapi import FastAPI, Request
from fastapi_utilities import add_timer_middleware

app = FastAPI()
add_timer_middleware(app, show_avg=True)


app.get("/")
def read_root():
return {"message": "Hello, World!"}



Response Logs:

INFO: (fastapi-utilities) "GET - /" :: Time Taken :: 0.97 ms
INFO: :: Average Response Time :: 0.97 ms

0.1.0

* **Repeated Tasks**: Easily trigger periodic tasks on server startup.

from fastapi_utilities.repeat import repeat_every

router.on_event('startup')
repeat_every(seconds=3)
async def print_hello():
print("hello")

Links

Releases

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.