Fastapi-utilities

Latest version: v0.3.0

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

Scan your dependencies

Page 1 of 2

0.3.0

What's Changed
* [✨Update✨] How to use with Latest FastAPI version by priyanshu-panwar in https://github.com/priyanshu-panwar/fastapi-utilities/pull/15
* Bump idna from 3.4 to 3.7 by dependabot in https://github.com/priyanshu-panwar/fastapi-utilities/pull/16
* Include the invalid cron expression in the exception message by benjamb in https://github.com/priyanshu-panwar/fastapi-utilities/pull/21
* Bump certifi from 2023.7.22 to 2024.7.4 by dependabot in https://github.com/priyanshu-panwar/fastapi-utilities/pull/19
* Resolve `imports` by priyanshu-panwar in https://github.com/priyanshu-panwar/fastapi-utilities/pull/23

New Contributors
* benjamb made their first contribution in https://github.com/priyanshu-panwar/fastapi-utilities/pull/21

**Full Changelog**: https://github.com/priyanshu-panwar/fastapi-utilities/compare/0.2.0...0.3.0

What's Changed
* [✨Update✨] How to use with Latest FastAPI version by priyanshu-panwar in https://github.com/priyanshu-panwar/fastapi-utilities/pull/15
* Bump idna from 3.4 to 3.7 by dependabot in https://github.com/priyanshu-panwar/fastapi-utilities/pull/16
* Include the invalid cron expression in the exception message by benjamb in https://github.com/priyanshu-panwar/fastapi-utilities/pull/21
* Bump certifi from 2023.7.22 to 2024.7.4 by dependabot in https://github.com/priyanshu-panwar/fastapi-utilities/pull/19
* Resolve `imports` by priyanshu-panwar in https://github.com/priyanshu-panwar/fastapi-utilities/pull/23

New Contributors
* benjamb made their first contribution in https://github.com/priyanshu-panwar/fastapi-utilities/pull/21

**Full Changelog**: https://github.com/priyanshu-panwar/fastapi-utilities/compare/0.2.0...0.3.0

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.1

* **Cron Jobs**: Easily trigger cron jobs on server startup using **repeat_at** by providing a cron expression.

from fastapi_utilities import repeat_at

router.on_event("startup")
repeat_at(cron="*/2 * * * *") every 2nd minute
async def hey():
print("hey")

Page 1 of 2

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.