GRAPHQL2PYTHON
graphql2python is a tool that generates python code out of your GraphQL schema. If you are using python as GraphQL client you can to generate pydantic data-model with graphql2python. The documentation for graphql2python can be found at https://denisart.github.io/graphql2python.
GraphQL query generation moved to https://github.com/denisart/graphql-query
The special example for gql users here.
Quickstart
Install with pip
pip install graphql2python
Create the following file
# graphql2python.yaml
schema: ./schema.graphql
output: ./model.py
and run the following command
graphql2python render --config ./graphql2python.yaml
Config reference
Global keywords
| keyword | description |
|---|---|
schema |
A path to the target GraphQL schema file. |
output |
A file name for output py file. |
license_file |
An optional path to a file with license for output py file. |
options |
Optional options for render of output py file. |
Options keywords
| keywords | description |
|---|---|
max_line_len |
The maximum of line length of output py file. Default is 120. |
name_suffix |
A suffix for invalid field name (as python object name). Default is "_". |
each_field_optional |
Each fields of interfaces and objects are optional. Default is false. |
add_from_dict |
Add from_dict (dict -> model) method to the general class. Default is false. |
add_to_dict |
Add to_dict (model -> dict) method to the general class. Default is false. |
scalar_pytypes |
A dict with python types for custom GraphQL scalars. Maps from scalar name to python type name. Default is empty dict. |
fields_setting |
Settings for interfaces or objects fields. Maps from object name to a dict with setting. Default is empty dict. |
fields_setting keywords for some object name
| keywords | desciption |
|---|---|
alias |
An alias for a field (see Field.alias for pydantic). Default is null. |
new_name |
A new name for a field. Default is null. |
An example for graphql2python.yaml config:
# graphql2python.yaml
schema: ./schema/schema.graphql
output: ./model/model.py
license_file: ./LICENSE
options:
scalar_pytypes:
String: str
Float: float
Int: int
ID: str
Boolean: bool
DateTime: datetime
Date: date
max_line_len: 79
each_field_optional: true
fields_setting:
MyObjectName:
from:
alias: from
new_name: correct_from
Metadata
Release files for graphql2python 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphql2python-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for graphql2python-0.0.6-py3-none-any.whl |
Release files / graphql2python-0.0.6-py3-none-any.whl
| Download URL | graphql2python-0.0.6-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2a19fa7998a05f1be61cf306c09ee2e74a94ccc29b1e2dba93d9c9932e09c6f
|
|
BLAKE2b-256 checksum How to use checksums |
586316785a1a39ac1147dc66c62f0a9edf2f64dba419470aeff919cd86469bb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.16
|
Security for graphql2python 0.0.6
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.