Skip to main content
Pre-release

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

greff

I wanted an animal name, but most of them already used in pypi :(, the name pronounced greph

what is it

greff creates python classes from graphql response.

what is it not

  • doesn't check for typing, you have pydantic for it
  • dataclass, although you can use the dataclasses syntax to create classes greff is for graphql and it adds graphql attributes behind the sence

current stage

in the current stage its not ready for release, it is only possible (for now) to query data

vision / example

import requests
import greff


@greff.define_type(queryname="authors")
class ParentAuthor(greff.Model):
    name: str
    age: int = 0


@greff.define_type()
class Author(ParentAuthor):
    extra_field: str


@greff.define_type()
class SimpleAuthor(ParentAuthor):
    pass


class MyGraphqlClient(greff.HTTPClient):

  # we implement the graphql posting function ourself
  # since it can very from diffrent implementations
  def request(self, query: str) -> dict:
      response = requests.post("http://localhost:8000/graphql", json={"query": query}, verify=False)
      response.raise_for_status()
      return response.json()


# create our charryplate graphql client
graphql = MyGraphqlClient()

# graphql equivelent
# query {
#   authors {
#     ... frag
#   }
# }
# fragment frag on Author {
#   name
# }
#
query = graphql.query((
        (ParentAuthor, (
            ParentAuthor.query.name,
        )),
    ),
)

# graphql response
# {
#   "data": {
#     "authors": [
#       {
#         "name": "Michael Crichton",
#         "__typename": "Author"
#       }
#     ]
#   }
# }
for author in query:
    print(type(author), author.name)

output

<class '__main__.Author'> Michael Crichton

why did it return Author instance and not ParentAuthor instance?

if you look closely at the response

{
  "data": {
    "authors": [
      {
        "name": "Michael Crichton",
        "__typename": "Author"
      }
    ]
  }
}

ParentAuthor is implementor for Author and SmallAuthor and in our query the __typename returned Author, so greff automatically created the correct python instace

Metadata

Release files for greff 0.0.6a0

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

Source distribution (sdist)

Source distribution for greff 0.0.6a0
File Size Uploaded Provenance Actions
greff-0.0.6a0.tar.gz 6.0 kB Without provenance Details for greff-0.0.6a0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for greff 0.0.6a0
File Interpreter ABI Platform Actions
greff-0.0.6a0-py3-none-any.whl Python 3 none any Details for greff-0.0.6a0-py3-none-any.whl

Total release size: 13.5 kB

Release files / greff-0.0.6a0.tar.gz

Download URL greff-0.0.6a0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9bf1b5020b1929ff6d91d9f9281cdfed2da61b2b0d6fa2135a83ec1913f36337
BLAKE2b-256 checksum
How to use checksums
bf26561f0de2438566571d9ec73d19585cea508f2675964e894055d564dddf18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.6 Linux/6.6.9-arch1-1

Release files / greff-0.0.6a0-py3-none-any.whl

Download URL greff-0.0.6a0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4dfa82cbbddb9b106ef730d4eb807f0964516167cee34b788bbf0851441bc604
BLAKE2b-256 checksum
How to use checksums
45f6001582256dd4b299d518e8bd173efe5f8b3210d43e7a9f10880397e85c90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.6 Linux/6.6.9-arch1-1

Security for greff 0.0.6a0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
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