{ "info": { "author": "Rami Chowdhury", "author_email": "rami@upside.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries" ], "description": "# ![Graphene Logo](http://graphene-python.org/favicon.png) graphene-pydantic [![Build status](https://circleci.com/gh/upsidetravel/graphene-pydantic.svg?style=svg)](https://circleci.com/gh/upsidetravel/graphene-pydantic) [![PyPI version](https://badge.fury.io/py/graphene-pydantic.svg)](https://badge.fury.io/py/graphene-pydantic) [![Coverage Status](https://coveralls.io/repos/upsidetravel/graphene-pydantic/badge.svg?branch=master&service=github)](https://coveralls.io/github/upsidetravel/graphene-pydantic?branch=master)\n\n\n\nA [Pydantic](https://pydantic-docs.helpmanual.io/) integration for [Graphene](http://graphene-python.org/).\n\n## Installation\n\n```bash\npip install \"graphene-pydantic\"\n```\n\n## Examples\n\nHere is a simple Pydantic model:\n\n```python\nimport pydantic\n\nclass PersonModel(pydantic.BaseModel):\n id: uuid.UUID\n first_name: str\n last_name: str\n\n```\n\nTo create a GraphQL schema for it you simply have to write the following:\n\n```python\nimport graphene\nfrom graphene_pydantic import PydanticObjectType\n\nclass Person(PydanticObjectType):\n class Meta:\n model = PersonModel\n # only return specified fields\n only_fields = (\"name\",)\n # exclude specified fields\n exclude_fields = (\"id\",)\n\nclass Query(graphene.ObjectType):\n people = graphene.List(Person)\n\n def resolve_people(self, info):\n return get_people() # function returning `PersonModel`s\n\nschema = graphene.Schema(query=Query)\n```\n\nThen you can simply query the schema:\n\n```python\nquery = '''\n query {\n people {\n firstName,\n lastName\n }\n }\n'''\nresult = schema.execute(query)\n```\n\n### Forward declarations and circular references\n\n`graphene_pydantic` supports forward declarations and circular references, but you will need to call the `resolve_placeholders()` method to ensure the types are fully updated before you execute a GraphQL query. For instance:\n\n``` python\nclass NodeModel(BaseModel):\n id: int\n name: str\n labels: 'LabelsModel'\n \nclass LabelsModel(BaseModel):\n node: NodeModel\n labels: typing.List[str]\n \nclass Node(PydanticObjectType):\n class Meta:\n model = NodeModel\n \nclass Labels(PydanticObjectType):\n class Meta:\n model = LabelsModel\n \n\nNode.resolve_placeholders() # make the `labels` field work\nLabels.resolve_placeholders() # make the `node` field work\n```\n\n### Full Examples\n\nPlease see [the examples directory](./examples) for more. \n\n### License\n\nThis project is under the [Apache License](./LICENSE.md).\n\n### Third Party Code\n\nThis project depends on third-party code which is subject to the licenses set forth in [Third Party Licenses](./THIRD_PARTY_LICENSES.md).\n\n### Contributing\n\nPlease see the [Contributing Guide](./CONTRIBUTING.md). Note that you must sign the [CLA](./CONTRIBUTOR_LICENSE_AGREEMENT.md).\n\n### Caveats\n\nNote that even though Pydantic is perfectly happy with fields that hold mappings (e.g. dictionaries), because [GraphQL's type system doesn't have them](https://graphql.org/learn/schema/) those fields can't be exported to Graphene types. For instance, this will fail with an error `Don't know how to handle mappings in Graphene`: \n\n``` python\nimport typing\nfrom graphene_pydantic import PydanticObjectType\n\nclass Pet:\n pass\n\nclass Person:\n name: str\n pets_by_name: typing.Dict[str, Pet]\n \nclass GraphQLPerson(PydanticObjectType): \n class Meta:\n model = Person\n```\n\nHowever, note that if you use `exclude_fields` or `only_fields` to exclude those values, there won't be a problem:\n\n``` python\nclass GraphQLPerson(PydanticObjectType):\n class Meta:\n model = Person\n exclude_fields = (\"pets_by_name\",)\n```\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/upsidetravel/graphene-pydantic", "keywords": "api,graphql,protocol,rest,relay,graphene,pydantic,model", "license": "Apache-2.0", "maintainer": "Rami Chowdhury", "maintainer_email": "rami@upside.com", "name": "graphene-pydantic", "package_url": "https://pypi.org/project/graphene-pydantic/", "platform": "", "project_url": "https://pypi.org/project/graphene-pydantic/", "project_urls": { "Homepage": "https://github.com/upsidetravel/graphene-pydantic", "Repository": "https://github.com/upsidetravel/graphene-pydantic" }, "release_url": "https://pypi.org/project/graphene-pydantic/0.0.4/", "requires_dist": [ "graphene (>=2.1.3,<3)", "pydantic (>=0.25,<0.30)" ], "requires_python": ">=3.6,<4.0", "summary": "Graphene Pydantic integration", "version": "0.0.4" }, "last_serial": 5635187, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "b3fb919f789e0a0cb54839765e1a2573", "sha256": "aace3143b8d22671cd5e410a93a6e2a2dc82063442bd5d3b71c9fa4dbefb639a" }, "downloads": -1, "filename": "graphene_pydantic-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b3fb919f789e0a0cb54839765e1a2573", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 8690, "upload_time": "2019-07-19T17:45:45", "url": "https://files.pythonhosted.org/packages/8e/85/cfbb2e5e9d6fba324931773bfe8cf225b22a1b99c153bf650eb60be81e6d/graphene_pydantic-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c7ee35d4a718f3b5215a09bef92eb515", "sha256": "ff2b61de0fdf172ed605c04d252080f15b6572c837ce272d76ccd2622194e91f" }, "downloads": -1, "filename": "graphene_pydantic-0.0.1.tar.gz", "has_sig": false, "md5_digest": "c7ee35d4a718f3b5215a09bef92eb515", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 7991, "upload_time": "2019-07-19T17:45:47", "url": "https://files.pythonhosted.org/packages/eb/77/513fe4f22d884d7df60d060bbc245463b187b42a978dfff28ee42ee4e7dc/graphene_pydantic-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "77e1bafcd641397925d5f460e72f5344", "sha256": "a2e01b1576f713d193741766bad1b9b4dc208cebfc421bd59f65a4d498d3258a" }, "downloads": -1, "filename": "graphene_pydantic-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "77e1bafcd641397925d5f460e72f5344", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 8691, "upload_time": "2019-07-19T17:51:37", "url": "https://files.pythonhosted.org/packages/30/ca/a96aae7a41b879586fd4015bfe44682a535e24234db0dbdb729c72da017d/graphene_pydantic-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "479b544b4a448960c1eaeb4fdbc164f9", "sha256": "ada41e19b5a7dd7c1fe1126eede49d97d7c9ce49c37b0dd3ad4e19f442a8ed17" }, "downloads": -1, "filename": "graphene_pydantic-0.0.2.tar.gz", "has_sig": false, "md5_digest": "479b544b4a448960c1eaeb4fdbc164f9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 7901, "upload_time": "2019-07-19T17:51:39", "url": "https://files.pythonhosted.org/packages/4c/0b/84fbf3541d518f5c27f4c1270d870ab1eb477257f36d7013b29a05ea15e7/graphene_pydantic-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "ad87c7c78342a1eead0198bb2339791f", "sha256": "c823860ab0376ce68eb93a9e8855af113067f1953aad6832d59a1dbd4c7001c7" }, "downloads": -1, "filename": "graphene_pydantic-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "ad87c7c78342a1eead0198bb2339791f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 8691, "upload_time": "2019-07-19T18:57:45", "url": "https://files.pythonhosted.org/packages/b9/b1/bf97ad91dee168c633815d38b75a2f0a09efd9cf0e7f8b88861326bc3124/graphene_pydantic-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a256767f260e96ca3e5b1d87c4653852", "sha256": "8b783cbcbcbb2152984bd88f724c64113db3cc675a97203442072eeb6271304a" }, "downloads": -1, "filename": "graphene_pydantic-0.0.3.tar.gz", "has_sig": false, "md5_digest": "a256767f260e96ca3e5b1d87c4653852", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 7901, "upload_time": "2019-07-19T18:57:47", "url": "https://files.pythonhosted.org/packages/bc/cc/78774dd6de5c0d76f1ca06a6df05568f1bf04f8f0544eb95434f3bbfcd23/graphene_pydantic-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "5177511b9553e6c42d07a0fd04fb698b", "sha256": "3cd58a3e5041096eb5d94a5a7079c975e595486f9a20a343eef553888b4e6d69" }, "downloads": -1, "filename": "graphene_pydantic-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "5177511b9553e6c42d07a0fd04fb698b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 9853, "upload_time": "2019-08-05T16:19:21", "url": "https://files.pythonhosted.org/packages/c9/e3/75654bb4815d1ee5dec92fa6766e1a4ab1e4493e2770ad759675ef8e8a33/graphene_pydantic-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cbc248f598fd6d062abc5ee8e8f23903", "sha256": "26b55796c2a50e31fd79d5900b12d6b3e1bfdfbfe78aaa01238cab6b2c8bf044" }, "downloads": -1, "filename": "graphene_pydantic-0.0.4.tar.gz", "has_sig": false, "md5_digest": "cbc248f598fd6d062abc5ee8e8f23903", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 9862, "upload_time": "2019-08-05T16:19:23", "url": "https://files.pythonhosted.org/packages/03/6c/85cfd9c07451f35c88560f0c0c0815ccec3de627595a9774f744c0497b27/graphene_pydantic-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5177511b9553e6c42d07a0fd04fb698b", "sha256": "3cd58a3e5041096eb5d94a5a7079c975e595486f9a20a343eef553888b4e6d69" }, "downloads": -1, "filename": "graphene_pydantic-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "5177511b9553e6c42d07a0fd04fb698b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 9853, "upload_time": "2019-08-05T16:19:21", "url": "https://files.pythonhosted.org/packages/c9/e3/75654bb4815d1ee5dec92fa6766e1a4ab1e4493e2770ad759675ef8e8a33/graphene_pydantic-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cbc248f598fd6d062abc5ee8e8f23903", "sha256": "26b55796c2a50e31fd79d5900b12d6b3e1bfdfbfe78aaa01238cab6b2c8bf044" }, "downloads": -1, "filename": "graphene_pydantic-0.0.4.tar.gz", "has_sig": false, "md5_digest": "cbc248f598fd6d062abc5ee8e8f23903", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 9862, "upload_time": "2019-08-05T16:19:23", "url": "https://files.pythonhosted.org/packages/03/6c/85cfd9c07451f35c88560f0c0c0815ccec3de627595a9774f744c0497b27/graphene_pydantic-0.0.4.tar.gz" } ] }