New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql2python

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql2python

Tools for GraphQL client in python.

  • 0.0.6
  • PyPI
  • Socket score

Maintainers
1

GRAPHQL2PYTHON

Build tag last-commit license

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

keyworddescription
schemaA path to the target GraphQL schema file.
outputA file name for output py file.
license_fileAn optional path to a file with license for output py file.
optionsOptional options for render of output py file.

Options keywords

keywordsdescription
max_line_lenThe maximum of line length of output py file. Default is 120.
name_suffixA suffix for invalid field name (as python object name). Default is "_".
each_field_optionalEach fields of interfaces and objects are optional. Default is false.
add_from_dictAdd from_dict (dict -> model) method to the general class. Default is false.
add_to_dictAdd to_dict (model -> dict) method to the general class. Default is false.
scalar_pytypesA dict with python types for custom GraphQL scalars. Maps from scalar name to python type name. Default is empty dict.
fields_settingSettings 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

keywordsdesciption
aliasAn alias for a field (see Field.alias for pydantic). Default is null.
new_nameA 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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc