Skip to main content

⚠️ DEPRECATION NOTICE ⚠️

This package has been deprecated in favor of prism-py, which provides improved functionality, better architecture, and continued maintenance.

API Forge

PyPI version GitHub: API Forge License: MIT Downloads

Overview

API Forge is a Python library built on top of FastAPI that streamlines database model management and API route generation. It provides a comprehensive type system for managing API responses, reducing boilerplate code, and ensuring type safety throughout your application.

The library automatically generates API routes, database models, and metadata endpoints, significantly reducing development time while maintaining code quality and type safety.

Key Features

  • Automatic Model Generation: Creates SQLAlchemy and Pydantic models from your existing database schema
  • Dynamic Route Generation: Automatically generates FastAPI routes for tables, views, and functions
  • Database Function Support: Native support for PostgreSQL functions, procedures, and triggers
  • Metadata API: Built-in routes to explore your database structure programmatically
  • Flexible Database Connection: Support for PostgreSQL, MySQL, and SQLite with connection pooling
  • Advanced Type System: Comprehensive type handling including JSONB and Array types
  • Schema-based Organization: Route organization based on database schemas
  • Full Type Hinting: Complete type hint support for better IDE integration

Installation

Install API Forge using pip:

pip install api-forge

Quick Start

Here's how to quickly set up an API with API Forge:

from fastapi import FastAPI
from forge import *  # import mod prelude (main structures)


# ? DB Forge ----------------------------------------------------------------------------------
# Configure database connection
db_manager = DBForge(
    config=DBConfig(
        db_type="postgresql",
        driver_type="sync",
        database="mydb",
        user="user",
        password="password",
        host="localhost",
        port=5432,
        pool_config=PoolConfig(
            pool_size=5,
            max_overflow=10,
            pool_timeout=30,
            pool_pre_ping=True
        )
    )
)
db_manager.log_metadata_stats()  # Log db metadata statistics

# ? Model Forge -------------------------------------------------------------------------------
model_forge = ModelForge(
    db_manager=db_manager,
    # * Define the schemas to include in the model...
    include_schemas=['public', 'app', 'another_schema'],
)
model_forge.log_schema_tables()  # detailed log of the tables in the schema
model_forge.log_schema_views()  # detailed log of the views in the schema
model_forge.log_schema_fns()  # detailed log of the functions in the schema
model_forge.log_metadata_stats()  # Log model metadata statistics


# ? Main API Forge ----------------------------------------------------------------------------
app: FastAPI = FastAPI()  # * Create a FastAPI app (needed when calling the script directly)

app_forge = Forge(  # * Create a Forge instance
    app=app,
    info=ForgeInfo(
        PROJECT_NAME="MyAPI",
        VERSION="1.0.0"
    )
)

# * The main forge store the app and creates routes for the models (w/ the static type checking)
app_forge.gen_metadata_routes(model_forge)  # * add metadata routes (schemas, tables, views, fns)
app_forge.gen_health_routes(model_forge)  # * add health check routes
# * Route Generators... (table, view, function)
app_forge.gen_table_routes(model_forge)  # * add db.table routes (ORM CRUD)
app_forge.gen_view_routes(model_forge)  # * add db.view routes
app_forge.gen_fn_routes(model_forge)  # * add db.[fn, proc, trigger] routes

Then run the application using Uvicorn:

uvicorn myapi:app --reload

Or run the script directly:

if __name__ == "__main__":
    import uvicorn  # import the Uvicorn server (ASGI)
    uvicorn.run(
        app=app,
        host=app_forge.uvicorn_config.host,
        port=app_forge.uvicorn_config.port,
        reload=app_forge.uvicorn_config.reload
    )

Generated Routes

API Forge automatically generates the following types of routes:

Table Routes

  • POST /{schema}/{table} - Create
  • GET /{schema}/{table} - Read (with filtering)
  • PUT /{schema}/{table} - Update
  • DELETE /{schema}/{table} - Delete

View Routes

  • GET /{schema}/{view} - Read with optional filtering

Function Routes

  • POST /{schema}/fn/{function} - Execute function
  • POST /{schema}/proc/{procedure} - Execute procedure

Metadata Routes

  • GET /dt/schemas - List all database schemas and their structures
  • GET /dt/{schema}/{{tables, views, fns}} - List all tables, views, or functions in a schema

Health Check Routes

  • GET /health - Get API health status and version information
  • GET /health/ping - Basic connectivity check
  • GET /health/cache - Check metadata cache status
  • POST /health/clear-cache - Clear and reload metadata cache

License

API Forge is released under the MIT License. See the LICENSE file for details.

Metadata

Release files for api-forge 0.1.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 api-forge 0.1.1
File Size Uploaded Provenance
api_forge-0.1.1.tar.gz 30.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for api-forge 0.1.1
File Interpreter ABI Platform
api_forge-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 66.2 kB

Release files / api_forge-0.1.1.tar.gz

Download URL api_forge-0.1.1.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c7f4c9e12cc2efe75fc950ae568b5cf7b1477c9c5b0af98715913c20baec3cc4
BLAKE2b-256 checksum
How to use checksums
9f18cfdd8a329ab1ee5cb8dd4455c46c01589f9a44f8a49b4eb17d4e8dddb6b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.14

Release files / api_forge-0.1.1-py3-none-any.whl

Download URL api_forge-0.1.1-py3-none-any.whl
Size 35.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b815cfec6c1045feb7dcb9bd8cb10dac95f2110043f8503f16d4c38166ab2696
BLAKE2b-256 checksum
How to use checksums
8f8d8462776e7a19e8a2885b28ce0a3a9ec153d6fa834d8e37ce3a7c26c1a421
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.14

Security for api-forge 0.1.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.

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