# GraphQL to Pydantic Transformer & Pydantic to Query Builder
## Overview
The **GraphQL to Pydantic Transformer** is a Python package designed to simplify the process of transforming GraphQL
schemas in JSON format into Pydantic models. This tool is particularly useful for developers working with GraphQL
APIs who want to generate Pydantic models from GraphQL types for efficient data validation
and serialization/deserialization.
## Features
- Converts GraphQL schemas in JSON format into Pydantic models.
- Build query or mutation from pydantic dataclass
## Installation
You can install the **GraphQL to Pydantic Transformer** package via pip:
```bash
pip install graphql-pydantic-transformer
```
## Usage
### Cli tool to transform GraphQL JSON to Pydantic
```bash
graphql-pydantic-converter [-h] [-i INPUT_FILE] [-o OUTPUT_FILE] [--url URL] [--headers HEADERS [HEADERS ...] ]
options:
-h, --help show this help message and exit
-i INPUT_FILE, --input-file INPUT_FILE
-o OUTPUT_FILE, --output-file OUTPUT_FILE
--url URL
--headers HEADERS [HEADERS ...] # --headers "HeaderName: HeaderValue" "HeaderName: HeaderValue"
```
### Output from cli tool
```python
import typing
from pydantic import Field
from graphql_pydantic_converter.graphql_types import Input
from graphql_pydantic_converter.graphql_types import Mutation
from graphql_pydantic_converter.graphql_types import Payload
Boolean: typing.TypeAlias = bool
DateTime: typing.TypeAlias = typing.Any
Float: typing.TypeAlias = float
ID: typing.TypeAlias = str
Int: typing.TypeAlias = int
JSON: typing.TypeAlias = typing.Any
String: typing.TypeAlias = str
class CreateScheduleInput(Input):
name: String
workflow_name: String = Field(alias='workflowName')
workflow_version: String = Field(alias='workflowVersion')
cron_string: String = Field(alias='cronString')
enabled: typing.Optional[Boolean]
parallel_runs: typing.Optional[Boolean] = Field(alias='parallelRuns')
workflow_context: typing.Optional[String] = Field(alias='workflowContext')
from_date: typing.Optional[DateTime] = Field(alias='fromDate')
to_date: typing.Optional[DateTime] = Field(alias='toDate')
class Schedule(Payload):
name: typing.Optional[Boolean] = Field(response='String', default=True)
enabled: typing.Optional[Boolean] = Field(response='Boolean', default=True)
parallel_runs: typing.Optional[Boolean] = Field(response='Boolean', alias='parallelRuns', default=True)
workflow_name: typing.Optional[Boolean] = Field(response='String', alias='workflowName', default=True)
workflow_version: typing.Optional[Boolean] = Field(response='String', alias='workflowVersion', default=True)
cron_string: typing.Optional[Boolean] = Field(response='String', alias='cronString', default=True)
workflow_context: typing.Optional[Boolean] = Field(response='String', alias='workflowContext', default=True)
from_date: typing.Optional[Boolean] = Field(response='DateTime', alias='fromDate', default=True)
to_date: typing.Optional[Boolean] = Field(response='DateTime', alias='toDate', default=True)
status: typing.Optional[Boolean] = Field(response='Status', default=True)
class CreateScheduleMutation(Mutation):
_name: str = Field('createSchedule', const=True)
input: CreateScheduleInput
payload: Schedule
CreateScheduleInput.update_forward_refs()
CreateScheduleMutation.update_forward_refs()
Schedule.update_forward_refs()
```
### Query & Mutation builder
```python
from schedule_api import Schedule, CreateScheduleMutation, CreateScheduleInput
SCHEDULE: Schedule = Schedule(
name=True,
enabled=True,
workflowName=True,
workflowVersion=True,
cronString=True,
fromDate=False,
toDate=False,
status=False
)
mutation = CreateScheduleMutation(
payload=SCHEDULE,
input=CreateScheduleInput(
name='name',
workflowName='workflowName',
workflowVersion='workflowVersion',
cronString='* * * * *',
enabled=True,
parallelRuns=False,
)
)
mutation.render()
```
Created query
```graphql
mutation {
createSchedule(
input: {
name: "name"
workflowName: "workflowName"
workflowVersion: "workflowVersion"
cronString: "* * * * *"
enabled: true
parallelRuns: false
}
) {
name
enabled
parallelRuns
workflowName
workflowVersion
cronString
workflowContext
}
}
```
Raw data
{
"_id": null,
"home_page": "",
"name": "graphql-pydantic-transformer",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "graphql,pydantic",
"author": "Jozef Volak",
"author_email": "jozef.volak@elisapolystar.com",
"download_url": "https://files.pythonhosted.org/packages/b2/02/6e4b4b82c1f70532ff49624e343be33885ccb8d06125a7aaae0970281d63/graphql_pydantic_transformer-0.0.2.tar.gz",
"platform": null,
"description": "# GraphQL to Pydantic Transformer & Pydantic to Query Builder\n\n## Overview\n\nThe **GraphQL to Pydantic Transformer** is a Python package designed to simplify the process of transforming GraphQL \nschemas in JSON format into Pydantic models. This tool is particularly useful for developers working with GraphQL\nAPIs who want to generate Pydantic models from GraphQL types for efficient data validation \nand serialization/deserialization.\n\n\n## Features\n\n- Converts GraphQL schemas in JSON format into Pydantic models.\n- Build query or mutation from pydantic dataclass\n\n## Installation\n\nYou can install the **GraphQL to Pydantic Transformer** package via pip:\n\n```bash\npip install graphql-pydantic-transformer\n```\n\n## Usage\n\n### Cli tool to transform GraphQL JSON to Pydantic\n\n```bash\ngraphql-pydantic-converter [-h] [-i INPUT_FILE] [-o OUTPUT_FILE] [--url URL] [--headers HEADERS [HEADERS ...] ]\n\noptions:\n -h, --help show this help message and exit\n -i INPUT_FILE, --input-file INPUT_FILE \n -o OUTPUT_FILE, --output-file OUTPUT_FILE \n --url URL \n --headers HEADERS [HEADERS ...] # --headers \"HeaderName: HeaderValue\" \"HeaderName: HeaderValue\"\n```\n\n### Output from cli tool\n\n```python\nimport typing\n\nfrom pydantic import Field\nfrom graphql_pydantic_converter.graphql_types import Input\nfrom graphql_pydantic_converter.graphql_types import Mutation\nfrom graphql_pydantic_converter.graphql_types import Payload\n\nBoolean: typing.TypeAlias = bool\nDateTime: typing.TypeAlias = typing.Any\nFloat: typing.TypeAlias = float\nID: typing.TypeAlias = str\nInt: typing.TypeAlias = int\nJSON: typing.TypeAlias = typing.Any\nString: typing.TypeAlias = str\n\nclass CreateScheduleInput(Input):\n name: String\n workflow_name: String = Field(alias='workflowName')\n workflow_version: String = Field(alias='workflowVersion')\n cron_string: String = Field(alias='cronString')\n enabled: typing.Optional[Boolean]\n parallel_runs: typing.Optional[Boolean] = Field(alias='parallelRuns')\n workflow_context: typing.Optional[String] = Field(alias='workflowContext')\n from_date: typing.Optional[DateTime] = Field(alias='fromDate')\n to_date: typing.Optional[DateTime] = Field(alias='toDate')\n\nclass Schedule(Payload):\n name: typing.Optional[Boolean] = Field(response='String', default=True)\n enabled: typing.Optional[Boolean] = Field(response='Boolean', default=True)\n parallel_runs: typing.Optional[Boolean] = Field(response='Boolean', alias='parallelRuns', default=True)\n workflow_name: typing.Optional[Boolean] = Field(response='String', alias='workflowName', default=True)\n workflow_version: typing.Optional[Boolean] = Field(response='String', alias='workflowVersion', default=True)\n cron_string: typing.Optional[Boolean] = Field(response='String', alias='cronString', default=True)\n workflow_context: typing.Optional[Boolean] = Field(response='String', alias='workflowContext', default=True)\n from_date: typing.Optional[Boolean] = Field(response='DateTime', alias='fromDate', default=True)\n to_date: typing.Optional[Boolean] = Field(response='DateTime', alias='toDate', default=True)\n status: typing.Optional[Boolean] = Field(response='Status', default=True)\n\n\nclass CreateScheduleMutation(Mutation):\n _name: str = Field('createSchedule', const=True)\n input: CreateScheduleInput\n payload: Schedule\n\nCreateScheduleInput.update_forward_refs()\nCreateScheduleMutation.update_forward_refs()\nSchedule.update_forward_refs()\n\n```\n\n### Query & Mutation builder\n\n\n```python\nfrom schedule_api import Schedule, CreateScheduleMutation, CreateScheduleInput\n\nSCHEDULE: Schedule = Schedule(\n name=True,\n enabled=True,\n workflowName=True,\n workflowVersion=True,\n cronString=True,\n fromDate=False,\n toDate=False,\n status=False\n)\n\nmutation = CreateScheduleMutation(\n payload=SCHEDULE,\n input=CreateScheduleInput(\n name='name',\n workflowName='workflowName',\n workflowVersion='workflowVersion',\n cronString='* * * * *',\n enabled=True,\n parallelRuns=False,\n )\n)\n\nmutation.render()\n\n```\n\n\nCreated query\n\n```graphql\nmutation {\n createSchedule(\n input: {\n name: \"name\"\n workflowName: \"workflowName\"\n workflowVersion: \"workflowVersion\"\n cronString: \"* * * * *\"\n enabled: true\n parallelRuns: false\n }\n ) {\n name\n enabled\n parallelRuns\n workflowName\n workflowVersion\n cronString\n workflowContext\n }\n}\n```\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Convert pydantic schema to pydantic datamodel and build request from it",
"version": "0.0.2",
"project_urls": null,
"split_keywords": [
"graphql",
"pydantic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "106db455679152d22d23a2e73c36a89a1e3eeef9f9b6037e45e363c9e9de3c70",
"md5": "9c4320b420c636f6d4f79f7dc72366fd",
"sha256": "2e130314658f5e20dac0d154864504d032a33d457c54719e36c08c0703b92df1"
},
"downloads": -1,
"filename": "graphql_pydantic_transformer-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9c4320b420c636f6d4f79f7dc72366fd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 9263,
"upload_time": "2023-09-04T15:00:19",
"upload_time_iso_8601": "2023-09-04T15:00:19.564136Z",
"url": "https://files.pythonhosted.org/packages/10/6d/b455679152d22d23a2e73c36a89a1e3eeef9f9b6037e45e363c9e9de3c70/graphql_pydantic_transformer-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b2026e4b4b82c1f70532ff49624e343be33885ccb8d06125a7aaae0970281d63",
"md5": "56cece35ae231a2b7a49ba1d95748f44",
"sha256": "17c569eeea24cc90e201fb14ebdf7056e0a7d04415ac20d8dbba649eb44e4973"
},
"downloads": -1,
"filename": "graphql_pydantic_transformer-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "56cece35ae231a2b7a49ba1d95748f44",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 9373,
"upload_time": "2023-09-04T15:00:21",
"upload_time_iso_8601": "2023-09-04T15:00:21.259394Z",
"url": "https://files.pythonhosted.org/packages/b2/02/6e4b4b82c1f70532ff49624e343be33885ccb8d06125a7aaae0970281d63/graphql_pydantic_transformer-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-04 15:00:21",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "graphql-pydantic-transformer"
}