GraphQL Database Mapper - Generate GraphQL APIs from database models (SQLAlchemy, SQLModel, etc.)
Project description
GraphQL-DB
📚 Documentation | 📦 PyPI | 🔧 GitHub
SQLAlchemy integration for graphql-api with automatic schema generation, query optimization, and database features.
Features
- 🗄️ SQLAlchemy 2.0+ Integration - Full support for modern SQLAlchemy
- 🚀 Automatic Schema Generation - Database models become GraphQL types
- 📄 Relay Pagination - Built-in cursor-based pagination
- 🔍 Query Optimization - Automatic N+1 prevention
- 🎯 Advanced Filtering - Powerful filtering for complex queries
- 📊 Performance Optimized - Efficient patterns for large datasets
Installation
pip install graphql-db graphql-api sqlalchemy
Quick Start
from graphql_api import GraphQLAPI
from graphql_db.orm_base import DatabaseManager, ModelBase
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column
# Initialize database
db_manager = DatabaseManager(url="sqlite:///myapp.db")
# Define your model
class User(ModelBase):
__tablename__ = 'users'
name: Mapped[str] = mapped_column(String(100))
email: Mapped[str] = mapped_column(String(100), unique=True)
# Create tables
db_manager.create_all()
# Create GraphQL API
api = GraphQLAPI()
@api.type(is_root_type=True)
class Query:
@api.field
def users(self) -> list[User]:
"""Get all users."""
return User.query().all()
# Execute with session management
def run_query():
return api.execute('{ users { name email } }')
result = db_manager.with_db_session(run_query)()
Documentation
Visit the official documentation for comprehensive guides, examples, and API reference.
Key Topics
- Getting Started - Quick introduction and basic usage
- Models & Schema - Define database models
- Pagination - Implement Relay pagination
- Relationships - Handle model relationships
- Performance - Query optimization
- Examples - Real-world usage examples
- API Reference - Complete API documentation
Related Projects
GraphQL DB integrates with the GraphQL ecosystem:
- graphql-api - Core GraphQL schema building (required)
- graphql-http - Serve your database API over HTTP
- graphql-mcp - Expose as MCP tools for AI agents
Key Features
Automatic Type Mapping
SQLAlchemy models automatically become GraphQL types with proper field type mapping.
Relay Pagination
Built-in support for Relay-style cursor pagination for efficient handling of large datasets.
Session Management
Automatic database session handling via context managers prevents session management errors.
Query Optimization
Eager loading support prevents N+1 queries and optimizes relationship loading.
See the documentation for detailed guides and examples.
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphql_db-1.0.2.tar.gz.
File metadata
- Download URL: graphql_db-1.0.2.tar.gz
- Upload date:
- Size: 59.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c1b81480fa7d1cf638140316085cee15ee97403d6b5d42f4353104bb800453f
|
|
| MD5 |
2211ebfc3f6347b404109d7c11c795c6
|
|
| BLAKE2b-256 |
b4ebca129c1ca925cfbabc00f2da982fc8d3d51f61967acef29a80343093d510
|
File details
Details for the file graphql_db-1.0.2-py3-none-any.whl.
File metadata
- Download URL: graphql_db-1.0.2-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e210fb8f51c7a7489ec08ba8bf8d8eda4a7008d597ce751c5c6d961561fd30d
|
|
| MD5 |
016532ca8e48e13a66b53e57eaba767a
|
|
| BLAKE2b-256 |
cb9ae58df13c9a130d685f2b653441a63b49a45caa303622e27d7837ea1d94b1
|