prism-py


Nameprism-py JSON
Version 0.0.13 PyPI version JSON
download
home_pageNone
SummaryAutomatic API generator that creates a REST API mirror of a database
upload_time2025-11-06 00:58:53
maintainerNone
docs_urlNone
authorYrrrrrf
requires_python>=3.10
licenseMIT
keywords api rest database orm codegen
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">
  <img src="https://raw.githubusercontent.com/Yrrrrrf/prism-py/main/resources/img/prism.png" alt="Prism Icon" width="128" height="128" description="A prism that can take one light source and split it into multiple colors!">
  <div align="center">prism-py</div>
</h1>

<div align="center">

[![PyPI version](https://img.shields.io/pypi/v/prism-py)](https://pypi.org/project/prism-py/)
[![GitHub: Prism-py](https://img.shields.io/badge/GitHub-prism--py-181717?logo=github)](https://github.com/Yrrrrrf/prism-py)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://choosealicense.com/licenses/mit/)
[![Downloads](https://pepy.tech/badge/prism-py)](https://pepy.tech/project/prism-py)

</div>

## Overview

**prism-py** is a Python library for automatic API generation from database schemas. It creates a complete REST API that mirrors your database structure, handling tables, views, functions, and procedures with proper type safety and validation.

Built on top of [FastAPI](https://fastapi.tiangolo.com/), prism-py eliminates boilerplate code and provides a comprehensive type system for API development, allowing you to focus on business logic instead of API structure.

> **Note:** This library is part of the Prism ecosystem, which includes [**prism-ts**](https://github.com/Yrrrrrf/prism-ts), a TypeScript client library that consumes prism-py APIs with full type safety.

## Key Features

- **Automatic Route Generation**: Create CRUD endpoints for tables, views, functions, and procedures
- **Composite Primary Keys**: Full support for tables with multi-column primary keys.
- **String Length Validation**: Automatic server-side validation based on database schema (e.g., `VARCHAR(50)`).
- **Type Safety**: Full type handling with proper conversions between SQL and Python types
- **Database Independence**: Support for PostgreSQL, MySQL, and SQLite
- **Schema-Based Organization**: Routes organized by database schemas for clean API structure
- **Enhanced Filtering**: Sorting, pagination, and complex query support
- **Metadata API**: Explore your database structure programmatically
- **Health Monitoring**: Built-in health check endpoints
- **Zero Boilerplate**: Generate complete APIs with minimal code

## Installation

```bash
pip install prism-py
```

## Quick Start

Here's a minimal example to get you started:

```python
from fastapi import FastAPI
from prism import ApiPrism, PrismConfig, DbClient, DbConfig, PoolConfig, ModelManager

# Initialize FastAPI app
app = FastAPI()

# Configure database connection
db_client = DbClient(
    config=DbConfig(
        db_type="postgresql",
        driver_type="sync",
        database="yourdb",
        user="username",
        password="password",
        host="localhost",
        port=5432,
        pool_config=PoolConfig(
            pool_size=5,
            max_overflow=10,
            pool_pre_ping=True
        )
    )
)

# Create model manager with selected schemas
model_manager = ModelManager(
    db_client=db_client,
    include_schemas=["public", "app"]
)

# Initialize API generator
api_prism = ApiPrism(
    config=PrismConfig(
        project_name="My API",
        version="1.0.0",
        description="Auto-generated API for my database"
    ),
    app=app
)

# Generate all routes
api_prism.generate_all_routes(model_manager)

# Print welcome message with API documentation link
api_prism.print_welcome(db_client)
```

## Generated Routes

prism-py automatically creates the following types of routes:

### Table Routes
- `POST /{schema}/{table}` - Create a record
- `GET /{schema}/{table}` - Read records with filtering
- `PUT /{schema}/{table}` - Update records
- `DELETE /{schema}/{table}` - Delete records

### View Routes
- `GET /{schema}/{view}` - Read from view with optional filtering

### Function/Procedure Routes
- `POST /{schema}/fn/{function}` - Execute database function
- `POST /{schema}/proc/{procedure}` - Execute stored procedure

### Metadata Routes
- `GET /dt/schemas` - List all database schemas and structure
- `GET /dt/{schema}/tables` - List all tables in a schema
- `GET /dt/{schema}/views` - List all views in a schema
- `GET /dt/{schema}/functions` - List all functions in a schema
- `GET /dt/{schema}/procedures` - List all procedures in a schema

### Health Routes
- `GET /health` - Get API health status
- `GET /health/ping` - Basic connectivity check
- `GET /health/cache` - Check metadata cache status
- `POST /health/clear-cache` - Clear and reload metadata cache

## Usage Examples

See the [examples](./examples) directory for complete sample applications:

- **[Hub Example](./examples/hub.py)**: Shows complex database integration with multiple schemas
- **[Basic Example](./examples/main.py)**: Demonstrates essential setup and configuration

## The Prism Ecosystem

prism-py is part of the Prism ecosystem, designed to create a seamless bridge between your database and type-safe client applications:

- **prism-py** (Python): Server-side library for automatic API generation
- **prism-ts** (TypeScript, formerly ts-prism): Client-side library for consuming prism-py APIs with full type safety

Together, these libraries enable end-to-end type safety and eliminate boilerplate code across your full stack.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

<!-- todo: Add some simple example but using some SQLite database, so that users can try it out without needing to set up a database server. -->
<!-- todo: This will also allow for a simpler setup for the examples. -->

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "prism-py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "api, rest, database, orm, codegen",
    "author": "Yrrrrrf",
    "author_email": "Yrrrrrf <fer.rezac@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/f7/02/844718f33549ee05dc342d3451283851d49cb1790e30e415388667b05291/prism_py-0.0.13.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/Yrrrrrf/prism-py/main/resources/img/prism.png\" alt=\"Prism Icon\" width=\"128\" height=\"128\" description=\"A prism that can take one light source and split it into multiple colors!\">\n  <div align=\"center\">prism-py</div>\n</h1>\n\n<div align=\"center\">\n\n[![PyPI version](https://img.shields.io/pypi/v/prism-py)](https://pypi.org/project/prism-py/)\n[![GitHub: Prism-py](https://img.shields.io/badge/GitHub-prism--py-181717?logo=github)](https://github.com/Yrrrrrf/prism-py)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://choosealicense.com/licenses/mit/)\n[![Downloads](https://pepy.tech/badge/prism-py)](https://pepy.tech/project/prism-py)\n\n</div>\n\n## Overview\n\n**prism-py** is a Python library for automatic API generation from database schemas. It creates a complete REST API that mirrors your database structure, handling tables, views, functions, and procedures with proper type safety and validation.\n\nBuilt on top of [FastAPI](https://fastapi.tiangolo.com/), prism-py eliminates boilerplate code and provides a comprehensive type system for API development, allowing you to focus on business logic instead of API structure.\n\n> **Note:** This library is part of the Prism ecosystem, which includes [**prism-ts**](https://github.com/Yrrrrrf/prism-ts), a TypeScript client library that consumes prism-py APIs with full type safety.\n\n## Key Features\n\n- **Automatic Route Generation**: Create CRUD endpoints for tables, views, functions, and procedures\n- **Composite Primary Keys**: Full support for tables with multi-column primary keys.\n- **String Length Validation**: Automatic server-side validation based on database schema (e.g., `VARCHAR(50)`).\n- **Type Safety**: Full type handling with proper conversions between SQL and Python types\n- **Database Independence**: Support for PostgreSQL, MySQL, and SQLite\n- **Schema-Based Organization**: Routes organized by database schemas for clean API structure\n- **Enhanced Filtering**: Sorting, pagination, and complex query support\n- **Metadata API**: Explore your database structure programmatically\n- **Health Monitoring**: Built-in health check endpoints\n- **Zero Boilerplate**: Generate complete APIs with minimal code\n\n## Installation\n\n```bash\npip install prism-py\n```\n\n## Quick Start\n\nHere's a minimal example to get you started:\n\n```python\nfrom fastapi import FastAPI\nfrom prism import ApiPrism, PrismConfig, DbClient, DbConfig, PoolConfig, ModelManager\n\n# Initialize FastAPI app\napp = FastAPI()\n\n# Configure database connection\ndb_client = DbClient(\n    config=DbConfig(\n        db_type=\"postgresql\",\n        driver_type=\"sync\",\n        database=\"yourdb\",\n        user=\"username\",\n        password=\"password\",\n        host=\"localhost\",\n        port=5432,\n        pool_config=PoolConfig(\n            pool_size=5,\n            max_overflow=10,\n            pool_pre_ping=True\n        )\n    )\n)\n\n# Create model manager with selected schemas\nmodel_manager = ModelManager(\n    db_client=db_client,\n    include_schemas=[\"public\", \"app\"]\n)\n\n# Initialize API generator\napi_prism = ApiPrism(\n    config=PrismConfig(\n        project_name=\"My API\",\n        version=\"1.0.0\",\n        description=\"Auto-generated API for my database\"\n    ),\n    app=app\n)\n\n# Generate all routes\napi_prism.generate_all_routes(model_manager)\n\n# Print welcome message with API documentation link\napi_prism.print_welcome(db_client)\n```\n\n## Generated Routes\n\nprism-py automatically creates the following types of routes:\n\n### Table Routes\n- `POST /{schema}/{table}` - Create a record\n- `GET /{schema}/{table}` - Read records with filtering\n- `PUT /{schema}/{table}` - Update records\n- `DELETE /{schema}/{table}` - Delete records\n\n### View Routes\n- `GET /{schema}/{view}` - Read from view with optional filtering\n\n### Function/Procedure Routes\n- `POST /{schema}/fn/{function}` - Execute database function\n- `POST /{schema}/proc/{procedure}` - Execute stored procedure\n\n### Metadata Routes\n- `GET /dt/schemas` - List all database schemas and structure\n- `GET /dt/{schema}/tables` - List all tables in a schema\n- `GET /dt/{schema}/views` - List all views in a schema\n- `GET /dt/{schema}/functions` - List all functions in a schema\n- `GET /dt/{schema}/procedures` - List all procedures in a schema\n\n### Health Routes\n- `GET /health` - Get API health status\n- `GET /health/ping` - Basic connectivity check\n- `GET /health/cache` - Check metadata cache status\n- `POST /health/clear-cache` - Clear and reload metadata cache\n\n## Usage Examples\n\nSee the [examples](./examples) directory for complete sample applications:\n\n- **[Hub Example](./examples/hub.py)**: Shows complex database integration with multiple schemas\n- **[Basic Example](./examples/main.py)**: Demonstrates essential setup and configuration\n\n## The Prism Ecosystem\n\nprism-py is part of the Prism ecosystem, designed to create a seamless bridge between your database and type-safe client applications:\n\n- **prism-py** (Python): Server-side library for automatic API generation\n- **prism-ts** (TypeScript, formerly ts-prism): Client-side library for consuming prism-py APIs with full type safety\n\nTogether, these libraries enable end-to-end type safety and eliminate boilerplate code across your full stack.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n<!-- todo: Add some simple example but using some SQLite database, so that users can try it out without needing to set up a database server. -->\n<!-- todo: This will also allow for a simpler setup for the examples. -->\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Automatic API generator that creates a REST API mirror of a database",
    "version": "0.0.13",
    "project_urls": {
        "Download": "https://github.com/Yrrrrrf/prism-py/releases",
        "Repository": "https://github.com/Yrrrrrf/prism-py"
    },
    "split_keywords": [
        "api",
        " rest",
        " database",
        " orm",
        " codegen"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b63fab4e8d45979c4c239949e3b1396ea07833da2dfcf786ca2dc933cb9b1d3c",
                "md5": "52c4500cccd8db43281f9145a6c7dc7f",
                "sha256": "22e44e50456cae4a6f8475ecebba3a8ba4c056fdc78b2e0cf205bc1f012b7439"
            },
            "downloads": -1,
            "filename": "prism_py-0.0.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "52c4500cccd8db43281f9145a6c7dc7f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 40736,
            "upload_time": "2025-11-06T00:58:51",
            "upload_time_iso_8601": "2025-11-06T00:58:51.631085Z",
            "url": "https://files.pythonhosted.org/packages/b6/3f/ab4e8d45979c4c239949e3b1396ea07833da2dfcf786ca2dc933cb9b1d3c/prism_py-0.0.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f702844718f33549ee05dc342d3451283851d49cb1790e30e415388667b05291",
                "md5": "eac6aebcf8ff503ad271c9de878fe921",
                "sha256": "596d6cba1960a7bb9ad7e8f33b272239ae6eedf40c1ec7639cd2b9ece7f9f1e1"
            },
            "downloads": -1,
            "filename": "prism_py-0.0.13.tar.gz",
            "has_sig": false,
            "md5_digest": "eac6aebcf8ff503ad271c9de878fe921",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 29938,
            "upload_time": "2025-11-06T00:58:53",
            "upload_time_iso_8601": "2025-11-06T00:58:53.523480Z",
            "url": "https://files.pythonhosted.org/packages/f7/02/844718f33549ee05dc342d3451283851d49cb1790e30e415388667b05291/prism_py-0.0.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-06 00:58:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Yrrrrrf",
    "github_project": "prism-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "prism-py"
}
        
Elapsed time: 1.06332s