Skip to main content

graphanno

Use Python 3.6+ type annotations to generate the graphene ObjectType classes.

Installation

You can install the project via pip by running:

pip install graphanno

Installation from source:

python setup.py install

Usage

The @graphanno.graph_annotations decorator works only with classes that contains type annotations. If there are no type annotations within the decorator target, NoAnnotationsError exception is raised. Arguments without annotations will be ignored.

To create the graphene.ObjectType object, you can just decorate your class with @graphanno.graph_annotations.

It is recommended to subclass graphanno.ObjectType to provide hints for IDE's. This is not mandatory, the @graphanno.graph_annotations will replace your decorated class with the ObjectType subclass anyway.

import graphene
import graphanno

# the class below...
@graphanno.graph_annotations
class Graphanno(graphanno.ObjectType):
    value: str

# ... is equivalent to:
class Graphene(graphene.ObjectType):
    value = graphene.String()

If you still need your class with type annotations, set __model__ variable to annotated class within the decorated one:

import graphene
import graphanno

class Annotated: # this class will be still available later
    value: str

# the class below...
@graphanno.graph_annotations
class Graphanno(graphanno.ObjectType): 
    """
    This class can inherit from graphene.ObjectType already, 
    but it won't change the @graph_annotations behavior.
    """
    __model__ = Annotated

# ... is equivalent to:
class Graphene(graphene.ObjectType):
    value = graphene.String()

If another class with the same name will be decorated, the SchemaClashError exception will be raised.

Additional parameters

  • __excluded_fields__ (tuple): names of the fields that will be excluded from schema. Private attributes are always excluded.
  • __ignore_unsupported__ (bool): do not raise an exception for unsupported annotations. Default False.

Supported annotations

The class decorated with @graph_annotations can use type annotations listed below.

  • str
  • int
  • float
  • bool
  • datetime.datetime
  • datetime.date
  • datetime.time
  • typing.List
  • custom classes with supported type annotations

Using unsupported annotations will raise the UnsupportedAnnotationError exception. To ignore this exception set __ignore_unsupported__ to True in the decorated class.

Metadata

Release files for graphanno 1.3.1

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

Source distribution (sdist)

Source distribution for graphanno 1.3.1
File Size Uploaded Provenance
graphanno-1.3.1.tar.gz 5.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for graphanno 1.3.1
File Interpreter ABI Platform
graphanno-1.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / graphanno-1.3.1.tar.gz

Download URL graphanno-1.3.1.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3b12e3ad53f987065c6f4d29de607aeb2b0054cdae3cc75f617fa4b0fe6f2042
BLAKE2b-256 checksum
How to use checksums
7178522405ba9631f814c6817c5bab35a42b6337a0ddd7f6d16db17ecf383c68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release files / graphanno-1.3.1-py3-none-any.whl

Download URL graphanno-1.3.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83ad805b399e76034fb95ddb24405bbc0a587c06351b396a9101fb454c20489d
BLAKE2b-256 checksum
How to use checksums
5c432a265a0675ca2e06822cb1e044f67d453e572d018041c9aee83818fda871
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Security for graphanno 1.3.1

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.

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