fastapi-modelrouter


Namefastapi-modelrouter JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/UweWindt/fastapi-modelrouter
SummaryFastAPI Router that creates CRUD routes for SqlAlchemy models
upload_time2023-05-06 21:20:29
maintainer
docs_urlNone
authorUwe Windt
requires_python
licenseMIT
keywords fastapi router sqlalchemy development
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # fastapi-modelrouter

## FastAPI Router that creates CRUD routes for SqlAlchemy models

### Features

- Generates direct from SqlAlchemy Models CRUD routes
- no need to write Pydantic Basemodels
- keep SqlAlchemy Models and routes in sync
- Simple to Use
- Supports composite primary keys
- Supports queryparams


## Installation
```
pip install fastapi-modelrouter
```

## Basic Usage
```
from fastapi import FastAPI
from modelrouter import ModelRouter

# setup Sqlalchemy Database
from sqlalchemy import create_engine, Column, String, Integer
from sqlalchemy.orm import sessionmaker, declarative_base

sqlalchemy_database_url = "sqlite:///:memory"

engine = create_engine(
    sqlalchemy_database_url, connect_args={"check_same_thread": False}
)
session_local = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()


# Define Project Model
class Project(Base):
    __tablename__ = 'project'
    projectno = Column(String, primary_key=True)
    project = Column(String)
    state = Column(Integer, default=0)
    owner = Column(String)


Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)


# Database session function
def get_db():
    db = session_local()
    try:
        yield db
    finally:
        db.close()


# Create FastApi
app = FastAPI()

# Create and include Modelrouter 
app.include_router(ModelRouter(Project, get_db))
```







            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/UweWindt/fastapi-modelrouter",
    "name": "fastapi-modelrouter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "fastapi router sqlalchemy development",
    "author": "Uwe Windt",
    "author_email": "uwe.windt@windisoft.de",
    "download_url": "https://files.pythonhosted.org/packages/00/2e/4a5539ae75e3ad90f000d9dc26ba345f27b779c7fb1477b4f60db153158d/fastapi-modelrouter-0.1.1.tar.gz",
    "platform": null,
    "description": "# fastapi-modelrouter\n\n## FastAPI Router that creates CRUD routes for SqlAlchemy models\n\n### Features\n\n- Generates direct from SqlAlchemy Models CRUD routes\n- no need to write Pydantic Basemodels\n- keep SqlAlchemy Models and routes in sync\n- Simple to Use\n- Supports composite primary keys\n- Supports queryparams\n\n\n## Installation\n```\npip install fastapi-modelrouter\n```\n\n## Basic Usage\n```\nfrom fastapi import FastAPI\nfrom modelrouter import ModelRouter\n\n# setup Sqlalchemy Database\nfrom sqlalchemy import create_engine, Column, String, Integer\nfrom sqlalchemy.orm import sessionmaker, declarative_base\n\nsqlalchemy_database_url = \"sqlite:///:memory\"\n\nengine = create_engine(\n    sqlalchemy_database_url, connect_args={\"check_same_thread\": False}\n)\nsession_local = sessionmaker(autocommit=False, autoflush=False, bind=engine)\n\nBase = declarative_base()\n\n\n# Define Project Model\nclass Project(Base):\n    __tablename__ = 'project'\n    projectno = Column(String, primary_key=True)\n    project = Column(String)\n    state = Column(Integer, default=0)\n    owner = Column(String)\n\n\nBase.metadata.drop_all(bind=engine)\nBase.metadata.create_all(bind=engine)\n\n\n# Database session function\ndef get_db():\n    db = session_local()\n    try:\n        yield db\n    finally:\n        db.close()\n\n\n# Create FastApi\napp = FastAPI()\n\n# Create and include Modelrouter \napp.include_router(ModelRouter(Project, get_db))\n```\n\n\n\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "FastAPI Router that creates CRUD routes for SqlAlchemy models",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/UweWindt/fastapi-modelrouter"
    },
    "split_keywords": [
        "fastapi",
        "router",
        "sqlalchemy",
        "development"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "002e4a5539ae75e3ad90f000d9dc26ba345f27b779c7fb1477b4f60db153158d",
                "md5": "cc8381fb3cb73cf916321299f8a7fe6f",
                "sha256": "548fc7ed17995e93ae0e4781a292f636be840ffe65a7dcbb47ca3e6779f3928a"
            },
            "downloads": -1,
            "filename": "fastapi-modelrouter-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "cc8381fb3cb73cf916321299f8a7fe6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5824,
            "upload_time": "2023-05-06T21:20:29",
            "upload_time_iso_8601": "2023-05-06T21:20:29.714747Z",
            "url": "https://files.pythonhosted.org/packages/00/2e/4a5539ae75e3ad90f000d9dc26ba345f27b779c7fb1477b4f60db153158d/fastapi-modelrouter-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-06 21:20:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "UweWindt",
    "github_project": "fastapi-modelrouter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "fastapi-modelrouter"
}
        
Elapsed time: 0.08837s