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.23.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

py2graphql-0.23.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py2graphql-0.23.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.5 Darwin/25.0.0

File hashes

Hashes for py2graphql-0.23.0.tar.gz
Algorithm Hash digest
SHA256 efe2daacf8db92d264aa1aac7cbc4d8112d1e21969c132422bce403c7e38e2f2
MD5 07f171b1a24afb1f634b792f9f3afc52
BLAKE2b-256 0e29d2fbc9480f627aeff6f6d7d561f9a9acf23d57cf6e2ae74aad9496a4ae99

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py2graphql-0.23.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.5 Darwin/25.0.0

File hashes

Hashes for py2graphql-0.23.0-py3-none-any.whl
Algorithm Hash digest
SHA256 791887d1b151347d41cd604b8ea85750c2a2309f85bc0f164c246e962bdaaf3d
MD5 ad131eeeaeb359e671126a21dad3a329
BLAKE2b-256 a9b6587283535c73198a3f713a39776ea405638547593f58013caa7f608a82ec

See more details on using hashes here.

Supported by

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