Generate CRUD routers for you schema in a simple way
Project description
FastAPI Simple CRUD Generator
Repository
Installation
pip install fastapi-simple-crud
Description
A package to generate a CRUD routers and endpoints in a very simple way. Based on SQLAlchemy asynchronous operation and schema.
How to use ?
from fastapi import FastAPI
from typing import Optional
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from simpleCRUD import SimpleCRUDGenerator, RouterMap
engine = create_async_engine("sqlite+aiosqlite:///./test.db", echo=True, future=True)
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
Base = declarative_base()
async def get_session() -> AsyncSession:
async with async_session() as session:
yield session
class Country(Base):
__tablename__ = "country"
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
name = Column(String(100), nullable=False)
class President(Base):
__tablename__ = "president"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
country_id = Column(Integer, ForeignKey("country.id"))
country = relationship("Country")
class People(Base):
__tablename__ = "people"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
age = Column(Integer)
country_id = Column(Integer, ForeignKey("country.id"))
country = relationship("Country")
app = FastAPI()
@app.on_event("startup")
async def startup():
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
## ULTRA SIMPLE OH MY GOD!
RouterMap.create_router_map_from_base(base=Base)
crudGenerator = SimpleCRUDGenerator(application=app, session_getter=get_session)
Results
- your endpoints
- your pydantic schema
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi-simple-crud-0.0.5.tar.gz
(113.9 kB
view hashes)
Built Distribution
Close
Hashes for fastapi-simple-crud-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ed5d2ea7f0c662234be343362f0972978b911b0a941eb170f856cbce8cdc546 |
|
MD5 | aa19b9aba7df617d19f66dc715ce5a3c |
|
BLAKE2b-256 | c2ed5fc10ccdeba364dc1db9097d8d8c9ee874c9050796736d5e8c1733328642 |
Close
Hashes for fastapi_simple_crud-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e77d2de5e24cdb502502baea0c0977d854bc9661b9ae66b1bfb1363f5a9d4a55 |
|
MD5 | 8614ce28db9ba6c96b1c734393f1ac9b |
|
BLAKE2b-256 | f0b82b0bd9d65ecc5a0adfe1355f2fa4cd404800f6ec0ffe611d8d1c214d1dbe |