Skip to main content

No project description provided

Project description

fastapi-crud-admin

Python CI pypi

Install


> pip install fastapi-crud-admin

Dependencies


  • FastAPI
  • SqlAlchemy
  • SqlLite

Features


  • CRUD API of all tables of SqlAlchemy with FastAPI
  • Custom interceptor for each CRUD API
  • Custom authentication

Example


1. Create a FastAPI Admin instance

from fastapi import FastAPI
from fastapi_crud_admin.admin import FastAPIAdmin

_app = FastAPI()

admin = FastAPIAdmin(
    app=_app,
    db_url="sqlite+aiosqlite:///./test.db"
)

2. Register sqlalchemy models in admin and create crud router for models

from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String

Base = declarative_base()

class Example(Base):
    __tablename__ = 'tb_example'
    index = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(length=200), nullable=False)

admin.register_schema_meta(models=[Example])
admin.register_schema_router()

3. (Optional) Register custom interceptor for crud router

from fastapi_crud_admin.enum import HttpMethod
from fastapi.responses import Response

def before_handler(http_method: HttpMethod, queries: dict, columns: dict) -> None:
    print(f"Before handler. Method: {http_method}")
    print(f"queries: {queries}")
    print(f"columns: {columns}")


def after_handler(response: Response) -> Response:
    print(f"After handler. Result: {response}")
    return response

admin.register_interceptor(table_name="tb_example", before_handler=before_handler, after_handler=after_handler)

4. (Optional) Register custom authentication for crud router

import bcrypt

def password_verifier(src: str, dest: str) -> bool:
    return bcrypt.checkpw(dest.encode('utf-8'), src.encode('utf-8'))

admin.register_authentication(
    user_name="admin",
    password=bcrypt.hashpw("admin".encode('utf-8'), bcrypt.gensalt()).decode('utf-8'),
    password_verifier=password_verifier
)

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_crud_admin-0.0.5.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

fastapi_crud_admin-0.0.5-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_crud_admin-0.0.5.tar.gz.

File metadata

  • Download URL: fastapi_crud_admin-0.0.5.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.8.16 Linux/6.5.0-1015-azure

File hashes

Hashes for fastapi_crud_admin-0.0.5.tar.gz
Algorithm Hash digest
SHA256 9ce84f7727505a28aff7a98b1c65bfd0d1d09e93a30db954786e82120b40da9a
MD5 763d12df908997c982e39db020af8c94
BLAKE2b-256 14c7d500592e31ac468d60a4d678e3d5ce511ae92586b42f8e9f8390f59ed5e9

See more details on using hashes here.

File details

Details for the file fastapi_crud_admin-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_crud_admin-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 688831472cbd1d3fb511aea30169129802cde3a1887975bc6f4d9a74752ed7e6
MD5 4d3fa507804e2310d3ecc31fc201e36e
BLAKE2b-256 ebe22d39e03d13e0ec24ecc8c194050e906f86ba0090a487583d0587e61ae144

See more details on using hashes here.

Supported by

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