Skip to main content

A package to generating FastAPI CRUD operations and routes

Project description

API Forge

PyPI version Documentation Status

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 forge import *  # import mod prelude (main structures)

# Initialize the main Forge application
app_forge = Forge(
    info=ForgeInfo(
        PROJECT_NAME="MyAPI",
        VERSION="1.0.0"
    )
)
app = app_forge.app

# 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
        )
    )
)

# Initialize model management
model_forge = ModelForge(
    db_manager=db_manager,
    include_schemas=['public', 'app']
)

# Set up API routes
api_forge = APIForge(model_forge=model_forge)

# Generate all routes
api_forge.gen_table_routes()  # CRUD routes for tables
api_forge.gen_view_routes()   # Read routes for views
api_forge.gen_fn_routes()     # Routes for database functions

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

License

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

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

api_forge-0.0.2.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

api_forge-0.0.2-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file api_forge-0.0.2.tar.gz.

File metadata

  • Download URL: api_forge-0.0.2.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for api_forge-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f8c852994175b60e947bc1e313395d4048fdd31a63bd1c64e4326036bad88a51
MD5 c8c63905edbef241fe4c608b8d73ef89
BLAKE2b-256 f8df77143708c33a2c5ec0a007d611484fa15ed767391ccc80f96aed5fc0b7be

See more details on using hashes here.

File details

Details for the file api_forge-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: api_forge-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for api_forge-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c7b145246e54bc3afacf3375266d2d9908cb807e28d32a9538eb8ade75635cca
MD5 a0a519e3555bc276d07f4a54702d0848
BLAKE2b-256 3eb1bed7132d79d201d17d89642fa4e7d5f9c0904259464597c757fbabc1cac4

See more details on using hashes here.

Supported by

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