freshcrate
Home > Frameworks > graphene

graphene

GraphQL Framework for Python

Description

# ![Graphene Logo](http://graphene-python.org/favicon.png) [Graphene](http://graphene-python.org) [![PyPI version](https://badge.fury.io/py/graphene.svg)](https://badge.fury.io/py/graphene) [![Coverage Status](https://coveralls.io/repos/graphql-python/graphene/badge.svg?branch=master&service=github)](https://coveralls.io/github/graphql-python/graphene?branch=master) [![](https://dcbadge.vercel.app/api/server/T6Gp6NFYHe?style=flat)](https://discord.gg/T6Gp6NFYHe) [���� Join the community on Discord](https://discord.gg/T6Gp6NFYHe) **We are looking for contributors**! Please check the current issues to see how you can help ������ ## Introduction [Graphene](http://graphene-python.org) is an opinionated Python library for building GraphQL schemas/types fast and easily. - **Easy to use:** Graphene helps you use GraphQL in Python without effort. - **Relay:** Graphene has builtin support for Relay. - **Data agnostic:** Graphene supports any kind of data source: SQL (Django, SQLAlchemy), Mongo, custom Python objects, etc. We believe that by providing a complete API you could plug Graphene anywhere your data lives and make your data available through GraphQL. ## Integrations Graphene has multiple integrations with different frameworks: | integration | Package | | ----------------- | --------------------------------------------------------------------------------------- | | SQLAlchemy | [graphene-sqlalchemy](https://github.com/graphql-python/graphene-sqlalchemy/) | | Mongo | [graphene-mongo](https://github.com/graphql-python/graphene-mongo/) | | Apollo Federation | [graphene-federation](https://github.com/graphql-python/graphene-federation/) | | Django | [graphene-django](https://github.com/graphql-python/graphene-django/) | Also, Graphene is fully compatible with the GraphQL spec, working seamlessly with all GraphQL clients, such as [Relay](https://github.com/facebook/relay), [Apollo](https://github.com/apollographql/apollo-client) and [gql](https://github.com/graphql-python/gql). ## Installation To install `graphene`, just run this command in your shell ```bash pip install "graphene>=3.1" ``` ## Examples Here is one example for you to get started: ```python import graphene class Query(graphene.ObjectType): hello = graphene.String(description='A typical hello world') def resolve_hello(self, info): return 'World' schema = graphene.Schema(query=Query) ``` Then Querying `graphene.Schema` is as simple as: ```python query = ''' query SayHello { hello } ''' result = schema.execute(query) ``` If you want to learn even more, you can also check the following [examples](examples/): - **Basic Schema**: [Starwars example](examples/starwars) - **Relay Schema**: [Starwars Relay example](examples/starwars_relay) ## Documentation Documentation and links to additional resources are available at https://docs.graphene-python.org/en/latest/ ## Contributing After cloning this repo, create a [virtualenv](https://virtualenv.pypa.io/en/stable/) and ensure dependencies are installed by running: ```sh virtualenv venv source venv/bin/activate pip install -e ".[test]" ``` Well-written tests and maintaining good test coverage is important to this project. While developing, run new and existing tests with: ```sh pytest graphene/relay/tests/test_node.py # Single file pytest graphene/relay # All tests in directory ``` Add the `-s` flag if you have introduced breakpoints into the code for debugging. Add the `-v` ("verbose") flag to get more detailed test output. For even more detailed output, use `-vv`. Check out the [pytest documentation](https://docs.pytest.org/en/latest/) for more options and test running controls. Regularly ensure your `pre-commit` hooks are up to date and enabled: ```sh pre-commit install ``` You can also run the benchmarks with: ```sh pytest graphene --benchmark-only ``` Graphene supports several versions of Python. To make sure that changes do not break compatibility with any of those versions, we use `tox` to create virtualenvs for each Python version and run tests with that version. To run against all Python versions defined in the `tox.ini` config file, just run: ```sh tox ``` If you wish to run against a specific version defined in the `tox.ini` file: ```sh tox -e py39 ``` Tox can only use whatever versions of Python are installed on your system. When you create a pull request, GitHub Actions pipelines will also be running the same tests and report the results, so there is no need for potential contributors to try to install every single version of Python on their own system ahead of time. We appreciate opening issues and pull requests to make graphene even more stable & useful! ### Building Documentation The documentation is generated using the excellent [Sphinx](http://www.s

Release History

VersionChangesUrgencyDate
3.4.3Imported from PyPI (3.4.3)Low4/21/2026
v3.4.3## What's Changed A proper error will now be raised when invalid UUIDs are passed as input variables. * Do not raise AttributeError when parsing non-string UUIDs by @phihag in https://github.com/graphql-python/graphene/pull/1582 ## New Contributors * @phihag made their first contribution in https://github.com/graphql-python/graphene/pull/1582 **Full Changelog**: https://github.com/graphql-python/graphene/compare/v3.4.2...v3.4.3Low11/9/2024
v3.4.2## What's Changed Graphene now supports overriding the Union options! * Overridable Union meta by @that-one-arab in https://github.com/graphql-python/graphene/pull/1583 ## New Contributors * @that-one-arab made their first contribution in https://github.com/graphql-python/graphene/pull/1583 **Full Changelog**: https://github.com/graphql-python/graphene/compare/v3.4.1...v3.4.2Low11/9/2024
v3.4.1## What's Changed This release brings a regression fix for `DateTime` parsing in python versions before 3.11, caused by the removal of `aniso8601`. The issue was introduced in `3.4.0`. If you are using the `DateTime` scalar together with a `Python <= 3.10`, please update Graphene to this version. * fix: use dateutil-parse for < 3.11 support by @erikwrede in https://github.com/graphql-python/graphene/pull/1581 **Full Changelog**: https://github.com/graphql-python/graphene/compare/v3.4.0Low10/27/2024
v3.4.0## What's Changed This release brings housekeeping changes and support for Python 3.13. Thanks to all contributors who made this release happen, and special thanks to @dulmandakh for bringing our CI up to modern standards. ## Full PR Changelist * remove pytz by @wongcht in https://github.com/graphql-python/graphene/pull/1520 * docs: update docstring for `type` arg of `Field` by @andrewswait in https://github.com/graphql-python/graphene/pull/1527 * CI: bump GH actions by @dulmandakh in httLow10/18/2024
v3.3.0This release brings two new features and several fixes and semantic upgrades due to new Python features. Thanks to everyone that contributed! 😊 ## Default value for InputObjectTypes ⚠️⚠️**ACTION REQUIRED**⚠️⚠️ In GraphQL, inputs can have fields which are optional. Currently, if those fields are not specified in the query, they are passed to the python inputs as `None`. This renders them indistinguishable from fields that are actually passed to the query with a value of `null`. While the Low7/26/2023
v3.2.2This release provides some internal refactoring to the relay types to improve support for adding custom fields to them.Low3/13/2023
v3.2.1## What's Changed Non-required `InputFields` and `Arguments` can now be marked as deprecated by passing the `deprecation_reason` keyword argument to the constructor. * Complete deprecated fields and arguments support by @vhutov in https://github.com/graphql-python/graphene/pull/1472 ## New Contributors * @vhutov made their first contribution in https://github.com/graphql-python/graphene/pull/1472 **Full Changelog**: https://github.com/graphql-python/graphene/compare/v3.2.0...v3.2.1Low12/11/2022
v3.2.0## What's Changed ### Support for custom global IDs in `relay.Node` The global ID type of a `Node` can now be customized: ```python class CustomNode(Node): class Meta: global_id_type = CustomGlobalIDType class User(ObjectType): class Meta: interfaces = [CustomNode] name = String() @classmethod def get_node(cls, _type, _id): return self.users[_id] ``` ##### Available Types Currently, the following types are available: - Low12/9/2022
v3.1.1## What's changed ### Dataloader Graphene now includes an updated version of `aiodataloader` by Syrus Akbary under `graphene.utils.dataloader` due to inactivity of the old repository. The update fixes an issue some users experienced when trying to use `dataloader` in conjunction with pytest (https://github.com/syrusakbary/aiodataloader/issues/13). Further contributions and updates to dataloader in this repo are welcome! ### Enums A custom typename can now be added when using `from_enum`: Low9/8/2022
v3.1.0## What's Changed * Various spelling and grammar fixes for the documentation. by @justinrmiller in https://github.com/graphql-python/graphene/pull/1324 * Chore: Refactor Multi Expression Code ✨ by @yezz123 in https://github.com/graphql-python/graphene/pull/1387 * Add Python 3.9 and 3.10 to the test matrix by @Cito in https://github.com/graphql-python/graphene/pull/1401 * fix UPGRADE-v2.0.md by @conao3 in https://github.com/graphql-python/graphene/pull/1405 * fix: default value for argument Low5/30/2022
v3.0.0# [Release notes](https://github.com/graphql-python/graphene/wiki/v3-release-notes) The full release notes including an upgrade guide can be found here: https://github.com/graphql-python/graphene/wiki/v3-release-notes ## What's Changed * Graphene v3 following v3 graphql-core by @mvanlonden in https://github.com/graphql-python/graphene/pull/1048 * Fix typos by @minho42 in https://github.com/graphql-python/graphene/pull/1066 * Remove AbstractType by @jkimbo in https://github.com/graphql-pythoLow11/13/2021
v3.0.0b8## Changes * fix: `graphql-core` dependency resolution. (#1377) All changes: https://github.com/graphql-python/graphene-django/compare/v3.0.0b7...v3.0.0b8Low9/30/2021
v2.1.9# Changelog * Add support for Python 3.10 * Propagate arguments of relay.NodeField to Field (#1036) (#1307)Low7/16/2021
v3.0.0b7## Changes * fix(Decimal): parse integers as decimal. (#1295) All changes: https://github.com/graphql-python/graphene-django/compare/v3.0.0b6...v3.0.0b7Low1/6/2021
v3.0.0b6## Changes * Fix subscribe with arguments (#1251) * Add BigInt type (#1261) * Add UnforgivingExecutionContext (#1255) All changes: https://github.com/graphql-python/graphene-django/compare/v3.0.0b5...v3.0.0b6Low10/21/2020
v3.0.0b5## Changes * Subscription revamp (#1235) Full changelog: https://github.com/graphql-python/graphene-django/compare/v3.0.0b4...v3.0.0b5Low8/6/2020
v3.0.0b4## Changes * Improve enum compatibility (#1153) * Rename variables called type to type_ (#1216) * Fix ObjectType meta arguments (#1219) * Add Base64 scalar (#1221) * Pin graphql-core to >v3.1.2 Full changelog: https://github.com/graphql-python/graphene-django/compare/v3.0.0b3...v3.0.0b4Low7/14/2020
v3.0.0b3## Changes * Fix DateTime Scalar parse_literal methods (#1199) (#1200) * Remove to_const function (#1212) Full changelog: https://github.com/graphql-python/graphene-django/compare/v3.0.0b2...v3.0.0b3Low6/25/2020
v3.0.0b2Third beta release for Graphene v3. Changes: https://github.com/graphql-python/graphene/compare/v3.0.0b1...v3.0.0b2 ## Highlights: * Allow fast ObjectType creation based on dataclasses (#1157) Contributes to an estimated 3x speedup with initialising ObjectTypes!Low5/9/2020
v3.0.0b1Second beta release for Graphene v3. Changes: https://github.com/graphql-python/graphene/compare/v3.0.0b0...v3.0.0b1 ## Highlights: * Added subscription support! https://github.com/graphql-python/graphene/pull/1107 Thanks to @rob-blackbourn for this fantasic contribution * Remove subclass polyfill #1156 * The `source` attribute now uses the default resolver function #1155 Low4/6/2020
v3.0.0b0First beta release of Graphene based on GraphQL-Core v3.1Low3/4/2020
v3.0.0a1Second Graphene alpha release compatible with GraphQL-Core v3.0Low3/4/2020
v3.0.0a0First Graphene alpha release compatible with GraphQL-Core v3.0 (graphql-core-next)Low8/17/2019
v2.1.8# Changelog * Bump pinned aniso8601 version * Allow mutations to apply the interfaces META argument to have the payload object type implement the desired interfacesLow8/17/2019
v2.1.7Update graphql-relay dependency to fix incompatibility.Low7/15/2019
v2.1.6# Changelog * Fix malformed version on aniso8601 requirement (#995) 431e93c # Documentation * Revise documentation (#969) 5cb7d91 * Expose livehtml autobuild in Makefile + Add API autodoc (#971) da1359e Full changelog: https://github.com/graphql-python/graphene/compare/v2.1.5...v2.1.6Low6/14/2019
v2.1.5# Changelog * Add Decimal type d728b84e48cb107a66f0fa5d22b19b89ba2abd1c * Allow Union types to have descriptions 8d4b9cdc77c1a978a9ae6808ecaf5d3ed8841cd2 * Add type documentation for Relay fields 131cbebc88229db1bbc86f432d0c5700a9f0f84b * Mutation description now defaults to docstring 37a6c01839687505da496d94dfd6c9f4383ca74c * Fix Windows support ae7a5d71c773fb3b8710a67bed8c800f2af068c2 * The default resolver for ObjectTypes now handles dicts and objects ca9188a6150485132c27b3dddf1496419Low6/5/2019
v2.1.3# Changelog * Added `crunch` and `deduplicator` utitlities https://github.com/graphql-python/graphene/commit/fa5f5b0acbede77a27d2f6e24d651ac8d6ea8c74 https://github.com/graphql-python/graphene/commit/2e41db8d95daa3ab09c294118e20b7c38387e00a * Permit subclassing arguments from Mutations https://github.com/graphql-python/graphene/commit/4346832f71564b63d6025c2c9ff88d1ffd241136 * Added precommit https://github.com/graphql-python/graphene/commit/ae7395f9da812a68f873f92cfaf8279896ce1d64 * Moved `Low7/19/2018
v2.1.2Bugfix release to fix a couple of issues. Thanks to the effort of contributors for this new release @jlowin @nxtman123 @danpalmer @dan98765 @femesq 🎉 # Changelog * Don't overwrite fields on InputObject #752 * Incorrectly formatted error message #751 * Fix warning output #748 # Docs and Internal * Update contributing docs about using tox and sync tox pytest cmd with travis #744 * Add isort precommit hook & run on all files #743 * Add flake8 pre-commit hook and manually edit fileLow6/14/2018
v2.1.1A small bugfix release to fix a couple of issues. Thanks to the effort of contributors for this new release @nikordaris @dan98765 @femesq @devArtoria 🎉 # Changelog * Fix `default_value` on `NonNull` fields (9408ba70d165284ff7ab5efd159a62e1d40a9a7f) * Add pre-commit tool to repository, and run on all files (#730) * Added partial support to Dynamic type (#725) # Docs * Improve v2 migrations docs (#732) * Add Graphene-Mongo to integrations list (#711)Low5/25/2018
v2.1.0This is a minor release, fixing a lot of small issues, with better support for `Date`, `DateTime` and `Time` scalars and tons of improvements on docs. Thanks to the effort of contributors for this new release @jkimbo @danpalmer @g-- @dfee @Prince-Leto @simonwoerpel @pjdelport @anisjonischkeit @abawchen 🎉 # Changelog * Extend support for subclassing `InputObjectType` meta a16c5ba00be1d963d438c5e96962b79d1b145cc3 * Raise better error if type is missing from Schema d6968c2e92486dda40725c9efLow3/30/2018
v2.0.1# Changelog * Prevent breaking changes for future releases 71177fe9776d8cf958ac3054885f891f49c1ef4d * Support for Enum description lambda f79eb57c063f1e2d1594fc19d1c1863feb5fc862 * Added `Date` type in datetime 045d5fffbec0d32550b19421fa01a088f5cd0d8c * Improved ObjectType Container initialization 3ee94131ae511d2d83116730dcc4a50258ced5af (Fix for #585) * Non provided fields in `InputObjectType` value should be `None` (rather than the Field) b5abccb1dc733522df19d56e0906890531a700d3 * ImprovLow11/15/2017
v2.0.0# v2.0.0 🎉 Please read the upgrade guide to learn how to upgrade: https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md * Simpler Graphene types implementation (thanks to `__init_subclass__`, and a polyfill implementation for Python 2). * Simplified resolver API * Type Options from class arguments (only available in Python 3) And... Subscriptions!!Low10/25/2017
v1.4.1# Changelog * Added type consistency for `Argument`s #467 * Include LICENSE in manifest for source bundles d7dff53f46967601a9b289a075a8bf7190431282 * Improved test framework to support thenables returned when executing queries 645bfddfe955e5a51b13a7d2e58714cdbb7166ab * Improved ClientIDMutation tests 6c2b940a03ee708bb8788836bb7a298d5aed9c57 * Fixed Argument output name 985252920ce2e2701388e2e20f3cc74419ff3b85 (**important**, please check #490) # Docs * Update Relay doc link 505253678750Low6/28/2017
v1.4.0# Changelog * Improved `Enum`s comparison and getters afed25a18015643749439288a9536235232dd493 * First version of Graphene test `Client` (`graphene.test.Client`) dfcd7f256340301d7551e2af383e4e84454db097 * Added `possible_types` option in `ObjectType.Meta` that mimics `is_type_of` -> `isinstance(root, possible_types)` a7511d3a2c2eb59ad8342d3db85f18ea477ae379 * Allow node inner types to be lazy e92b03bed5e1a12c558d5b1c8a03b92eecff3218 * Updated `promise` package requirement to 2.0 * UpdateLow4/20/2017
v1.3.0# Changelog * Fix docstring whitespace 62e58bd95325604186563f54c898736db9d39585 * Added optional default_resolver in `ObjectType` 98825fa4bc0f2fd6f88d11796b1093e0d63a51ee * Fix `ObjectType` inheritance with custom Meta ad251e9a8dd46d212e39da67945df4fc3e02b361 48efec307ce245bfe692f75b5dc07c14d8bce15b * Fixed circular Union/Interfaces d4d8a76a0936b8b8b90e6b316003c31c21e30500 * Improved `lazy_import` to accept also dotted attributes d594a0eca86102ce2ebf9633018437eef8997f42 * Use `Promise.resoLow4/7/2017
v1.2.0# Changelog - `partial` functions can be now passed as type to `Field` 774e9bf4639ca459d0a12a10e090d9ab671b6459 - Added a generic scalar type: `GenericScalar` (based on @hung-phan work for `JSON`) - Refactor mounted type logic 27cd00b9f9b9050b10f9c3c86841c5e4199be086 - Set `Union` as `UnmountedType` 2ef0e23dcf036aa41e7ee96dd2468c7177021829 - Allow class method to be used as field source f728542ce7d431359ed32f3522bea12d629eb329 - Added a `test` packages to setup.py as `extra_requires` (so it's eaLow2/21/2017
v1.1.3# Changelog - Added new `Time` type to `graphene.types.datetime` 692d7e76ad06b0b0eb777c14197d041913519868 - Fixed promise-like compatibility in relay Connections 3df62d26a7962f1273df972da21b25ac75bc9cf3 (Related `promise` fix: https://github.com/syrusakbary/promise/commit/8b0d5da3dca2d99671b820478ef74353ac24c97b) Low12/2/2016
v1.1.2# Changelog - Added type getter in the schema when accessing its attrs. 5e0923b56073f42ce25da6628c46ebed120b0654 Now is possible to access Graphene types in a schema by typing `schema.TYPE_NAME` directly. ## Breaking changes - Removed `register` method from `graphene.Schema` df2900e215c88f78dc3fe213df78c8ea9832f3ea Low11/23/2016
v1.1.1# Changelog - Fixed resolved interfaces and unions that have `is_type_of` defined in the inner types when used inside `List` or `NonNull` 67c0872c9fceed737b2300d118e6950ee20e97fe Low11/16/2016
v1.1.0# Changelog - Updated datetime with tests 95280e4f7c2a4b372902d590f0b0f8bc13a57a85 - Improved Dynamic Field tests 822b030938533d4b2b182bd6bf64172f8816c0f4 - Fixed Dynamic Arguments 0a80119f5eabbee2e34d0aa755afb9847ae2cf2c - Improved Promise Connection abstraction 760ccc83587396df9a2cbf5806b7f4fa73ba620e - Relay Edges should be non null 495361ef53ffc3edb3ffa0966cdcb0f67618056c - Fixed TOX dependencies d1a9bdb5c3d4c0bd04e165aff506d458b4ac93fe - Fixed typo in Union initialization 937e257d609c51ad81Low11/15/2016
v1.0.2# Changelog - Connection resolvers can now return a Connection instance instead of a Iterator c7929234294a181993158b4439c24006e9ed1ebd - Improved Arguments and List, NonNull instances to be comparable bd207b5f06a64dbbd610ea901f0d76c5b4918734 - Fixed overwritten `ConnectionField` arguments c961f0b3c60c3a7a6223d5218c912d69585aef5c - Fixed unbound `mutate` method in `Mutation` 999bca84c98d452634dd530e374ea6b649167c64 Low10/4/2016
v1.0.1# Changelog - Fixed requiring an overwrite of the `is_type_of` method in `ObjectType` in the case the resolver was returning an object that was not an instance of the type. [8030fea44318b9dfcda854c96dfa5091b266f95e] Low9/29/2016
v1.0More info here! http://graphene-python.org/blog/graphene-production-ready/ ## Upgrade Guide https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md Low9/26/2016
v0.10.2# Changelog - Fixed unregistered types in `graphene.Schema` https://github.com/graphql-python/graphene/commit/da09bc321001213f5dc7e199e63378283f8ba501 - Improved Django choices: - Use Django forcetext for choices https://github.com/graphql-python/graphene/commit/7f6598518e3704f256d966bcd4b136a109066216 - Fixed Django converter of field with grouped choices https://github.com/graphql-python/graphene/commit/9e715cd902be6c5bc8fd88d9783dfb92ad80e0f5 - Fixed ClientIDMutation GraphQL type name. htLow6/1/2016
v0.10.1# Changelog - Fixed bug when no middlewares are present https://github.com/graphql-python/graphene/commit/feb0825a639876ed02ea0914d4ce1163d1fd20ca - Add test for auto_camelcase flag https://github.com/graphql-python/graphene/commit/161f19845163ca0323483d7045e26bf52df1c6c9 Low6/1/2016
v0.10.0# Changelog Breaking: - Removed the plugin functionality, replaced by with Middleware. #176 Bug fixes: - Support `with_context` on ClientIDMutation.mutate_and_get_payload. https://github.com/graphql-python/graphene/commit/61e7beee7b9c83c55b7b47c3814f120e421400b6 - Added interfaces field into a ObjectType https://github.com/graphql-python/graphene/commit/10304eb8cf67f1bc563fe62aac8975ad23037f97 - Allow string references in InputTypes https://github.com/graphql-python/graphene/commit/d6740e9ff5Low5/21/2016
v0.9.1# Changelog - Fixed package compatibility issue 71153061568dddd166276cff9390f237fc3d7525 Low5/19/2016
v0.9.0# Changelog - Updated graphql-core version to `0.5.0`, with a improved way for executing queries - Added the `with_context` decorator for having the context appended into the resolver arguments Low5/19/2016
v0.8.0# Changelog This Graphene version improves the Django integration - Improved Django choice converter to GraphQL Enum type 68a9fb9fc4d25e0bbcd059183633c4531d7bbf3d - Added ability for a Enum to be mounted as a instance (field) in `ObjectTypes`,`InputObjectTypes` or an argument e1a693e57c86e73ff42611c87d66cffca103dfa9 - Added FileField support in Django models a1dd2b629320ad70de618c82dab8a0050b38f56d - Added support for Postgres fields in Django models 7f965003538c61614b5d31ad09c4e9d69fc831a0 - ALow4/3/2016

Dependencies & License Audit

Loading dependencies...

Similar Packages

boxsdkOfficial Box Python SDK10.6.0
drf-spectacularSane and flexible OpenAPI 3 schema generation for Django REST framework0.29.0
django-cors-headersdjango-cors-headers is a Django application for handling the server headers required for Cross-Origin Resource Sharing (CORS).4.9.0
schemathesisProperty-based testing framework for Open API and GraphQL based apps4.15.2
opsgenie-sdkPython SDK for Opsgenie REST API2.1.5