Socket
Socket
Sign inDemoInstall

sqlalchemy-graphqlapi

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqlalchemy-graphqlapi

Python DB-API and SQLAlchemy interface for GraphQL APIs.


Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc