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.
Metadata
Release files for graphql-db 1.0.2
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 | Actions |
|---|---|---|---|---|
| graphql_db-1.0.2.tar.gz | 59.7 kB | Without provenance | Details for graphql_db-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphql_db-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for graphql_db-1.0.2-py3-none-any.whl |
Total release size: 72.4 kB
Release files / graphql_db-1.0.2.tar.gz
| Download URL | graphql_db-1.0.2.tar.gz |
|---|---|
| Size | 59.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c1b81480fa7d1cf638140316085cee15ee97403d6b5d42f4353104bb800453f
|
|
BLAKE2b-256 checksum How to use checksums |
b4ebca129c1ca925cfbabc00f2da982fc8d3d51f61967acef29a80343093d510
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / graphql_db-1.0.2-py3-none-any.whl
| Download URL | graphql_db-1.0.2-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e210fb8f51c7a7489ec08ba8bf8d8eda4a7008d597ce751c5c6d961561fd30d
|
|
BLAKE2b-256 checksum How to use checksums |
cb9ae58df13c9a130d685f2b653441a63b49a45caa303622e27d7837ea1d94b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for graphql-db 1.0.2
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.