跳转到主要内容

Python DB-API和SQLAlchemy接口,用于GraphQL API。

项目描述

graphql-db-api PyPI版本 主要工作流程 codecov

Python DB API 2.0用于GraphQL API

此模块允许您使用SQL查询GraphQL API。

SQLAlchemy支持

此模块提供了一个SQLAlchemy方言。

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')

示例用法

查询连接

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)

查询列表

当我们使用查询参数查询“表”时,可以将给定的GQL查询标记为列表

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)

或者,我们可以在Engine级别设置它

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支持

为了与Superset一起使用,请安装此软件包,然后在SQLAlchemy URI中使用graphql协议,例如:graphql://swapi-graphql.netlify.app/.netlify/functions/index。我们安装了一个db_engine_spec,因此Superset应该能够识别该驱动程序。

路线图

  • 非连接顶级
  • 路径遍历(基本)
  • 路径遍历(基本+嵌套)
  • 路径遍历(列表/连接)
  • Authorization头中包含Bearer令牌
  • 高级认证(例如,带有令牌刷新)
  • 传递头(例如,在其他位置进行认证)
  • 过滤
  • 排序
  • 继电器分页

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

sqlalchemy-graphqlapi-0.0.1.dev5.tar.gz (12.9 kB 查看哈希值)

上传时间

构建分布

sqlalchemy_graphqlapi-0.0.1.dev5-py3-none-any.whl (11.1 kB 查看哈希值)

上传时间 Python 3

支持者