Skip to main content

Pythonic GraphQL Client

Project description

pypi

  1. GraphQL

  2. Django queryset love

  3. __getattr__ abuse

  4. ???

  5. Profit!!!

What

py2graphql is a Python GraphQL client that makes GraphQL feel better to use. It almost feels like you’re using Django’s ORM.

Installation

pip install py2graphql

Example

This Python equates to the following GraphQL.

from py2graphql import Query

Query().repository(owner='juliuscaeser', name='rome').pullRequest(number=2).values('title', 'url').commits(last=250).edges.node.commit.values('id', 'message', 'messageBody')
query {
  repository(owner: "juliuscaeser", name: "rome") {
    pullRequest(number: 2) {
      title
      url
      commits(last: 250) {
        edges {
          node {
            commit {
              id
              message
              messageBody
            }
          }
        }
      }
    }
  }
}

You can even use the library to do the HTTP requests:

from py2graphql import Client

headers = {
    'Authorization': 'token MY_TOKEN',
}
Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome').fetch()

It also supports Mutations:

from py2graphql import Client, Query

headers = {
    'Authorization': 'token MY_TOKEN',
}
client = Client(url=THE_URL, headers=headers)
mutation = Query(name='mutation', client=client)

And multiple queries in a single request:

from py2graphql import Client, Query

headers = {
    'Authorization': 'token MY_TOKEN',
}
query = Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome')
query.pullRequest(number=2).values('title', 'url')
query.releases(first=10).edges.node.values('name')
query.get_graphql()
query {
  repository(owner: "juliuscaeser", name: "rome") {
     pullRequest(number: 2) {
       title
       url
     }
     releases(first: 10) {
       edges {
         node {
           name
         }
       }
     }
   }
}

As well as GraphQL errors:

from py2graphql import Client, Query

headers = {
    'Authorization': 'token MY_TOKEN',
}
result = Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome').fetch()
result._errors
[{'message': "Field 'repository' is missing required arguments: name", 'locations': [{'line': 7, 'column': 3}]}]

Project details


Download files

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

Source Distribution

py2graphql-0.18.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

py2graphql-0.18.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file py2graphql-0.18.0.tar.gz.

File metadata

  • Download URL: py2graphql-0.18.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Darwin/20.6.0

File hashes

Hashes for py2graphql-0.18.0.tar.gz
Algorithm Hash digest
SHA256 77b924b80473b7f4dc06d58af9a023a1478d4ce5890c0cc74064cf9b9da222ad
MD5 f9e95d4506cf017ea7f659e2005a541c
BLAKE2b-256 37bd05c9baafd871c8d9566766928c275b3a6a3ae0be2f7f25b6a6b4f1f92fde

See more details on using hashes here.

File details

Details for the file py2graphql-0.18.0-py3-none-any.whl.

File metadata

  • Download URL: py2graphql-0.18.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Darwin/20.6.0

File hashes

Hashes for py2graphql-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 deeea2400b8939f6c9c092193e907fb2c49e32cbc2bfd6df148b99a73061b022
MD5 15401c548f989582ea464e0111432038
BLAKE2b-256 51bca711d91cd89be8261538d1026ff26da6783bf186aadddcccc1721fc9e842

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page