prism-py
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, 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, 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
pip install prism-py
Quick Start
Here's a minimal example to get you started:
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 recordGET /{schema}/{table}- Read records with filteringPUT /{schema}/{table}- Update recordsDELETE /{schema}/{table}- Delete records
View Routes
GET /{schema}/{view}- Read from view with optional filtering
Function/Procedure Routes
POST /{schema}/fn/{function}- Execute database functionPOST /{schema}/proc/{procedure}- Execute stored procedure
Metadata Routes
GET /dt/schemas- List all database schemas and structureGET /dt/{schema}/tables- List all tables in a schemaGET /dt/{schema}/views- List all views in a schemaGET /dt/{schema}/functions- List all functions in a schemaGET /dt/{schema}/procedures- List all procedures in a schema
Health Routes
GET /health- Get API health statusGET /health/ping- Basic connectivity checkGET /health/cache- Check metadata cache statusPOST /health/clear-cache- Clear and reload metadata cache
Usage Examples
See the examples directory for complete sample applications:
- Hub Example: Shows complex database integration with multiple schemas
- Basic Example: 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 file for details.
Metadata
Release files for prism-py 0.0.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| prism_py-0.0.14.tar.gz | 30.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prism_py-0.0.14-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 70.9 kB
Release files / prism_py-0.0.14.tar.gz
| Download URL | prism_py-0.0.14.tar.gz |
|---|---|
| Size | 30.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a379086901041b71e5debf0b1b4f6649839d6cf0b196ebc0ebfbfe953135946
|
|
BLAKE2b-256 checksum How to use checksums |
91bffccd511c4cff9729d76a659e0c429238868be8253ed2d98f8e8ec8c0b9f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / prism_py-0.0.14-py3-none-any.whl
| Download URL | prism_py-0.0.14-py3-none-any.whl |
|---|---|
| Size | 40.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7536caaa5f860491028495443cae2c5ea7966a2ab70f1130894dbc13b16519c7
|
|
BLAKE2b-256 checksum How to use checksums |
5e6da5e494f2e891da992b6975360edc0617bc733c767c07450da4f8946f9652
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for prism-py 0.0.14
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.