Skip to main content

graphql-codegen powered by pydantic

Project description

turms

codecov PyPI version Maintenance Maintainer PyPI pyversions PyPI status PyPI download month

Goal

Turms is a graphql-codegen inspired code generator for python that generates typed and serializable python code from your graphql schema and documents. Just define your query in standard graphql syntax and let turms create fully typed queries/mutation and subscriptions, that you can use in your favourite IDE.

Turms allows you to easily generate both server-side and client-side code for your GraphQL API.

Schema (Server) Generation:

Can generate the following types from your graphql SDL schema:

  • Enums
  • Inputs
  • Objects
  • Scalars
  • Directives

Sepcific generation supported for:

  • Strawberry
  • Graphene

Documents (Client) Generation

Can generate the following pydantic models from your graphql documents:

  • Enums
  • Inputs
  • Scalars
  • Fragments
  • Operations

Features

  • Fully typed, fully documented code generation
  • Schema and Document based code generation
  • Compatible with popular graphql libraries (strawberry, gql, rath, etc.)
  • Support for custom scalars, custom directives, ...
  • Powerful plugin system (e.g. custom Linting, custom formatting, etc.)
  • Operation functions like query, mutation, subscription (e.g. data= get_capsules())
  • Compliant with graphl-config
  • Code migration support (trying to merge updates into existing code)

Installation

pip install turms

turms is a pure development library and will not introduce any dependency on itself into your code, so we recommend installing turms as a development dependency.

poetry add -D turms

As of now turms only supports python 3.9 and higher (as we rely on ast unparsing)

Configuration

Turms relies on and complies with graphql-config and searches your current working dir for the graphql-config file.

Document based generation

Based on pydantic models

projects:
  default:
    schema: http://api.spacex.land/graphql/
    documents: graphql/**.graphql
    extensions:
      turms: # path for configuration for turms
        out_dir: examples/api
        plugins: # path for plugin configuration
          - type: turms.plugins.enums.EnumsPlugin
          - type: turms.plugins.inputs.InputsPlugin
          - type: turms.plugins.fragments.FragmentsPlugin
          - type: turms.plugins.operation.OperationsPlugin
          - type: turms.plugins.funcs.FuncsPlugin
        processors:
          - type: turms.processor.black.BlackProcessor
          - type: turms.processor.isort.IsortProcessor
        scalar_definitions:
          uuid: str
          timestamptz: str
          Date: str

Schema based generation

Based on strawberry models

projects:
  default:
    schema: beasts.graphql
    extensions:
      turms:
        skip_forwards: true
        out_dir: api
        stylers:
          - type: turms.stylers.capitalize.CapitalizeStyler
          - type: turms.stylers.snake_case.SnakeCaseStyler
        plugins:
          - type: turms.plugins.strawberry.StrawberryPlugin # generates a strawberry schema
        processors:
          - type: turms.processors.disclaimer.DisclaimerProcessor
          - type: turms.processors.black.BlackProcessor
          - type: turms.processors.isort.IsortProcessor
          - type: turms.processors.merge.MergeProcessor # merges the formated schema with already defined functions
        scalar_definitions:
          uuid: str
          _Any: typing.Any

Usage

Once you have configured turms you can generate your code by running

turms gen

Why Turms

In Etruscan religion, Turms (usually written as 𐌕𐌖𐌓𐌌𐌑 Turmś in the Etruscan alphabet) was the equivalent of Roman Mercury and Greek Hermes, both gods of trade and the messenger god between people and gods.

Transport Layer

Turms does not come with a default transport layer but if you are searching for an Apollo-like GraphQL Client you can check out rath, that works especially well with turms.

Examples

This github repository also contains some examples on how to use turms with popular libraries in the graphql ecosystem.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turms-0.8.3.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

turms-0.8.3-py3-none-any.whl (68.3 kB view details)

Uploaded Python 3

File details

Details for the file turms-0.8.3.tar.gz.

File metadata

  • Download URL: turms-0.8.3.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-48-generic

File hashes

Hashes for turms-0.8.3.tar.gz
Algorithm Hash digest
SHA256 a70d43451261a36197844dcac0d2c1fa06cd038d3bf10d3a23c3b5d57b510ae5
MD5 18ac5ea20cb1290abcfeefa2c0dfae38
BLAKE2b-256 eba4942ab6207d0c9505e8d1c006335d6cad58fc499231701fc2e7c768bfe084

See more details on using hashes here.

File details

Details for the file turms-0.8.3-py3-none-any.whl.

File metadata

  • Download URL: turms-0.8.3-py3-none-any.whl
  • Upload date:
  • Size: 68.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-48-generic

File hashes

Hashes for turms-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b5de9f6013f5956d3d80e51dba4ac535d491ffdf4a6c313906bc9231cb4425d6
MD5 d3912ad4d02144bb37610d1ca1995ca4
BLAKE2b-256 ec46a4a70d8517334616eefd8a5d17e787af38435bab5c82c54790dc8ebcf915

See more details on using hashes here.

Supported by

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