Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

graphql-db-api PyPI version main workflow codecov

A Python DB API 2.0 for GraphQL APIs

This module allows you to query GraphQL APIs using SQL.

SQLAlchemy support

This module provides a SQLAlchemy dialect.

from sqlalchemy.engine import create_engine

# Over HTTPS (default):
engine_https = create_engine('graphql://host:port/path')

# Over HTTP:
engine_http = create_engine('graphql://host:port/path?is_https=0')

# With a `Bearer` token in the `Authorization` header:
engine_http = create_engine('graphql://:token@host:port/path')

Example Usage

Querying Connections

from sqlalchemy import create_engine
from sqlalchemy import text

# We use GraphQL SWAPI (The Star Wars API) c/o Netlify:
engine = create_engine('graphql://swapi-graphql.netlify.app/.netlify/functions/index')

# Demonstration of requesting nested resource of homeworld
# and then selecting fields from it
query = "select name, homeworld__name from 'allPeople?include=homeworld'"

with engine.connect() as connection:
    for row in connection.execute(text(query)):
        print(row)

Querying Lists

We can mark a given GQL query as being a List when we query that "Table" using a query parameter:

from sqlalchemy import create_engine
from sqlalchemy import text

engine = create_engine('graphql://pet-library.moonhighway.com/')

# The default assumes top level is a Connection.
# For Lists, we must disable this:
query = "select id, name from 'allPets?is_connection=0'"

with engine.connect() as connection:
    for row in connection.execute(text(query)):
        print(row)

alternatively, we can set that at the Engine level:

from sqlalchemy import create_engine
from sqlalchemy import text

# We mark 'allPets' as being a List at the Engine level:
engine = create_engine(
    'graphql://pet-library.moonhighway.com/',
    list_queries=["allPets"],
)

query = "select id, name from allPets"

with engine.connect() as connection:
    for row in connection.execute(text(query)):
        print(row)

Superset support

In order to use with Superset, install this package and then use the graphql protocol in the SQLAlchemy URI like: graphql://swapi-graphql.netlify.app/.netlify/functions/index. We install a db_engine_spec so Superset should recognize the driver.

Roadmap

  • Non-Connections top level
  • Path traversal (basic)
  • Path traversal (basic + nested)
  • Path traversal (list / connection)
  • Bearer Tokens in Authorization Header
  • Advanced Auth (e.g. with token refresh)
  • Passing Headers (e.g. Auth in other locations)
  • Filtering
  • Sorting
  • Relay Pagination

Release files for sqlalchemy-graphqlapi 0.0.1.dev5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy-graphqlapi 0.0.1.dev5
File Size Uploaded
sqlalchemy-graphqlapi-0.0.1.dev5.tar.gz 12.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-graphqlapi 0.0.1.dev5
File Interpreter ABI Platform
sqlalchemy_graphqlapi-0.0.1.dev5-py3-none-any.whl Python 3 none any Details

Total release size: 24.1 kB

Release files / sqlalchemy-graphqlapi-0.0.1.dev5.tar.gz

Download URL sqlalchemy-graphqlapi-0.0.1.dev5.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b974e3c4205555932be61832670a4b84c1155d4645f62d07eb2e82adb9244906
BLAKE2b-256 checksum
How to use checksums
34b5aca9625c2ee544e6056731dc815fea6d800905d4795941981cfc4c112308
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.2

Release files / sqlalchemy_graphqlapi-0.0.1.dev5-py3-none-any.whl

Download URL sqlalchemy_graphqlapi-0.0.1.dev5-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d768cc1b3fb67f0dae45d142921c3cfd3bf87c2dde92362ac420c26e8485b7c2
BLAKE2b-256 checksum
How to use checksums
223949854d244b45af53ad8625500aa8a0bbc0e841c22d56c075c22edccd5bb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.2
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