Skip to main content

Utilities to make using fastapi a little easier.

Project description

fastapi-extras

A series of extras and utilities that make using fastapi a little bit easier

Features

  • Modular and Configurable Session Management
  • Synchronous Request Getter Utilities using Depends
  • Helpers for using pyderive dataclasses

Examples

Session Middleware

from fastapi import FastAPI
from fastapi_extras.session import SessionMiddleware

# drop in replacement for starlette SessionMiddleware
app = FastAPI()
app.add_middleware(SessionMiddleware)

# customizable and configurable storage interface
from fastapi_extras.session.fs import FileStore

app = FastAPI()
app.add_middleware(SessionMiddleware, store=FileStore())

Synchronous Getters

from fastapi import FastAPI, Request
from fastapi_extras.getters import form

app = FastAPI()

@app.post('/async')
async def async_form(request: Request):
    """collect form object using async function call"""
    form = await request.form()
    return form

@app.post('/sync')
def sync_form(request: Request, form = form()):
    """collect async form resource without async using dependency"""
    return form

Pyderive Helpers

from fastapi import FastAPI, Request
from fastapi_extras.session import SessionMiddleware
from fastapi_extras.getters import as_session
from pyderive.extensions.validate import BaseModel, IPv4

class Session(BaseModel):
    ip: IPv4

app = FastAPI()
app.add_middleware(SessionMiddleware)

@app.get('/start')
def start(request: Request) -> str:
    host = request.client.host if request.client else '127.0.0.1'
    request.session['ip'] = host
    return 'Session Started'

@app.get('/check')
def check(session: Session = as_session(Session)):
    return f'Your IPAddress is {session.ip!r}'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_extras3-0.3.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_extras3-0.3.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_extras3-0.3.0.tar.gz.

File metadata

  • Download URL: fastapi_extras3-0.3.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.20

File hashes

Hashes for fastapi_extras3-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d02263f1f32b4ac8ce65e6fadcd7a9a043c2a11b23b729b61b621d67218c1de9
MD5 1caf9478c3aec1b8b610b53ad0c4b1fa
BLAKE2b-256 45881d9d1cd0e3230c2ba8cb4f51be7f07675a1ba6868d07ddcb41e3b7b8b36d

See more details on using hashes here.

File details

Details for the file fastapi_extras3-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_extras3-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d3cf860ea1dc7ceebf01650c460f2937845cf799dd13495b072cb3178f12003
MD5 f9679ad7712e193f9810cfc3a0aaad67
BLAKE2b-256 e0d6492ddcbfec94aaab98ba749f0ee5c5291b997f61e32e14ae417de48040c6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page