Skip to main content

PyGraphile

Python Version PyPI version License: MIT

A Python library inspired by PostGraphile — automatically generates GraphQL APIs from your database schema.

Point PyGraphile at a SQLite file or a MariaDB/MySQL database, and get a fully working, ASGI-compatible GraphQL API. No schema writing, no manual resolvers.

🚧 Project Status

v0.6.2 — Early access. Core query API is working for SQLite, MariaDB, and MySQL. Mutations, filtering, and PostgreSQL are on the roadmap.

✨ Features

  • 🔍 Schema introspection — Automatically reads tables, columns, and types from your database
  • Instant GraphQL — Generates a complete, executable GraphQL schema with resolvers on the fly
  • 🗄️ Multi-database support — SQLite, MariaDB, and MySQL supported today
  • 🔤 Identifier sanitization — Table and column names with spaces or special characters are automatically converted to valid GraphQL names (e.g. "full name"full_name, "tabapi request log"TabapiRequestLog)
  • 🔌 ASGI native — Returns a standard ASGI app you can mount into FastAPI, Starlette, or any ASGI framework
  • 🐍 Pure Python — Supports Python 3.9 through 3.13+

🚀 Installation

SQLite (no extra dependencies)

pip install pygraphile

MariaDB / MySQL

pip install "pygraphile[mariadb]"
# or for mysql alias:
pip install "pygraphile[mysql]"

Using uv

uv add pygraphile              # SQLite only
uv add "pygraphile[mariadb]"   # with MariaDB/MySQL support

From source

git clone https://github.com/dshaw0004/pygraphile.git
cd pygraphile
uv pip install -e .

📖 Quick Start

SQLite

from pygraphile import PyGraphile
from fastapi import FastAPI
import uvicorn

app = FastAPI()

pg = PyGraphile('mydb.sqlite', db_type='sqlite', debug=True)
app.mount('/graphql', pg.get_query_app())

if __name__ == '__main__':
    uvicorn.run(app, port=8000)

MariaDB / MySQL

from pygraphile import PyGraphile
from fastapi import FastAPI
import uvicorn

app = FastAPI()

md = PyGraphile(
    'mariadb://user:password@127.0.0.1:3306/mydb',
    db_type='mariadb',  # or 'mysql'
    debug=True,
)
app.mount('/graphql', md.get_query_app())

if __name__ == '__main__':
    uvicorn.run(app, port=8000)

What gets generated

Given a table named "tabapi request log" with columns id INT and full name VARCHAR:

# Table and column names with spaces are sanitized automatically
type TabapiRequestLog {
  id: Int
  full_name: String
}

type Query {
  tabapi_request_log: [TabapiRequestLog]
}

Query it:

curl -X POST http://localhost:8000/graphql/ \
  -H "Content-Type: application/json" \
  -d '{"query":"{ tabapi_request_log { id full_name } }"}'

With debug=True, an Apollo GraphQL Explorer is also available at /graphql.

⚙️ API Reference

PyGraphile(db_name, db_type, migration_folder, debug)

Parameter Type Default Description
db_name str 'pygraphile.sqlite' SQLite file path, or MariaDB/MySQL connection URI
db_type str 'sqlite' 'sqlite', 'sqlite3', 'mariadb', or 'mysql'
migration_folder str 'nomigration' Reserved for future migration support
debug bool False Enables Apollo Explorer and verbose logging

pg.get_query_app()

Returns an ASGI-compatible Ariadne GraphQL app ready to be mounted.

Utility functions

from pygraphile import sanitize_field_name, sanitize_type_name

sanitize_field_name("full name")        # → "full_name"
sanitize_field_name("tabapi request log") # → "tabapi_request_log"
sanitize_type_name("tabapi request log")  # → "TabapiRequestLog"
sanitize_type_name("order-items")         # → "OrderItems"

🗺️ Roadmap

  • Project setup and structure
  • SQLite schema introspection and query resolvers
  • GraphQL schema generation
  • MariaDB & MySQL support
  • Identifier sanitization (spaces & special characters in table/column names)
  • Mutation support (INSERT / UPDATE / DELETE)
  • PostgreSQL support
  • Filtering & pagination
  • Authentication & authorization
  • Plugin system

🤝 Contributing

Contributions are welcome! This project is in early stages, so there's plenty of opportunity to shape its direction.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License — see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by PostGraphile — An amazing tool for PostgreSQL
  • Built with Ariadne for GraphQL execution
  • Tooling powered by uv

📬 Contact


Note: This project is under active development. APIs and features are subject to change.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygraphile-0.6.2.tar.gz (143.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygraphile-0.6.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file pygraphile-0.6.2.tar.gz.

File metadata

  • Download URL: pygraphile-0.6.2.tar.gz
  • Upload date:
  • Size: 143.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pygraphile-0.6.2.tar.gz
Algorithm Hash digest
SHA256 1ea75dab5f1f130de0e17dbbd0885766373378addb8cf0ebd720ff5bc72bdeef
MD5 400f2c1b5ce5dba78c423c2e32ace27d
BLAKE2b-256 d4acc6118eac32280b5fb808cb83d2c861ffbd9ff9528d6cd3e86498e6f4521d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygraphile-0.6.2.tar.gz:

Publisher: workflow.yml on dshaw0004/pygraphile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygraphile-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: pygraphile-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pygraphile-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 486f24c4501a3529d792c43e781609b753cd410b1a1721eaad1d22fa5638ff25
MD5 b833b9405120ab7654fb0fba3f08a9db
BLAKE2b-256 29aa0ab5031cb82564cc982d26270a3623e8cc80d0a860ab8a005b962534586f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygraphile-0.6.2-py3-none-any.whl:

Publisher: workflow.yml on dshaw0004/pygraphile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 files

0.5.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 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