Skip to main content

Sqlalchemy Fastapi Endpoint Factory

Auto generate FastAPI endpoint by SqlAlchemy model for data access

Installation

pip install sqlalchemy-fastapi-endpoint-factory

Or

uv add --dev sqlalchemy-fastapi-endpoint-factory

Example

Install an example for a quick launch.

uv add fastapi sqlalchemy uvicorn
# main.py
from fastapi import FastAPI
from sqlalchemy import Integer, Column, String, insert

from sqlalchemy_fastapi_endpoint_factory.main import make_endpoint
from sqlalchemy.orm import declarative_base
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

Base = declarative_base()


class SimpleModel(Base):
    __tablename__ = "simple_model"

    id = Column(Integer, primary_key=True)
    username = Column(String)
    email = Column(String)


engine = create_engine("sqlite:///:memory:", connect_args={"check_same_thread": False})
connection = engine.connect()
ScopedSession = scoped_session(
    sessionmaker(autocommit=False, autoflush=False, bind=connection)
)
SimpleModel.__table__.create(bind=engine, checkfirst=True)

# Test data
TEST_DATA = [
    {"id": 1, "username": "user1", "email": "user1@example.com"},
    {"id": 2, "username": "user2", "email": "user2@example.com"},
    {"id": 3, "username": "user3", "email": "user3@example.com"},
    {"id": 4, "username": "admin", "email": "admin@example.com"},
    {"id": 5, "username": "test", "email": "test@example.com"},
]
with engine.begin() as conn:
    conn.execute(insert(SimpleModel), TEST_DATA)


def execute_query(query):
    with ScopedSession() as session:
        result = session.execute(query).mappings()

    return [dict(row) for row in result]


app = FastAPI()
app.add_api_route(
    "/simple/filter",
    endpoint=make_endpoint(SimpleModel, execute_query),
    methods=["POST"],
)
uvicorn main:app

Visit page in browser:

http://localhost:8000/docs

http://localhost:8000/redoc

img.png

img.png

Metadata

Release files for sqlalchemy-fastapi-endpoint-factory 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy-fastapi-endpoint-factory 1.0.1
File Size Uploaded Provenance
sqlalchemy_fastapi_endpoint_factory-1.0.1.tar.gz 379.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-fastapi-endpoint-factory 1.0.1
File Interpreter ABI Platform
sqlalchemy_fastapi_endpoint_factory-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 385.2 kB

Release files / sqlalchemy_fastapi_endpoint_factory-1.0.1.tar.gz

Download URL sqlalchemy_fastapi_endpoint_factory-1.0.1.tar.gz
Size 379.9 kB
Tags Source
SHA-256 checksum
How to use checksums
09f6274827c684d70b76e6fbae14060930c45ad28503eb8626fc88f06a5d7bdc
BLAKE2b-256 checksum
How to use checksums
a3d25d6d3f5eb49a958427aa4b10c73ca62d38981c75815dde254178f2497a6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.3

Release files / sqlalchemy_fastapi_endpoint_factory-1.0.1-py3-none-any.whl

Download URL sqlalchemy_fastapi_endpoint_factory-1.0.1-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
168dcb84bbf2a12b151e0eea79142aa8e4c46f437962706116ca2313a64e8656
BLAKE2b-256 checksum
How to use checksums
7069aaf05e899099b3dca8d5be67c30360f9b77ead6662411d140494fb71d6f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.3

Security for sqlalchemy-fastapi-endpoint-factory 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page