Skip to main content

GraphQL-DB

PyPI version Python versions License: MIT

📚 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

GraphQL DB integrates with the GraphQL ecosystem:

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.

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)

Source distribution for graphql-db 1.0.2
File Size Uploaded
graphql_db-1.0.2.tar.gz 59.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for graphql-db 1.0.2
File Interpreter ABI Platform
graphql_db-1.0.2-py3-none-any.whl Python 3 none any Details

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}

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page