# ![Graphene Logo](http://graphene-python.org/favicon.png) Graphene-Django
[![build][build-image]][build-url]
[![pypi][pypi-image]][pypi-url]
[![Anaconda-Server Badge][conda-image]][conda-url]
[![coveralls][coveralls-image]][coveralls-url]
[build-image]: https://github.com/graphql-python/graphene-django/workflows/Tests/badge.svg
[build-url]: https://github.com/graphql-python/graphene-django/actions
[pypi-image]: https://img.shields.io/pypi/v/graphene-django.svg?style=flat
[pypi-url]: https://pypi.org/project/graphene-django/
[coveralls-image]: https://coveralls.io/repos/github/graphql-python/graphene-django/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/graphql-python/graphene-django?branch=master
[conda-image]: https://img.shields.io/conda/vn/conda-forge/graphene-django.svg
[conda-url]: https://anaconda.org/conda-forge/graphene-django
Graphene-Django is an open-source library that provides seamless integration between Django, a high-level Python web framework, and Graphene, a library for building GraphQL APIs. The library allows developers to create GraphQL APIs in Django quickly and efficiently while maintaining a high level of performance.
## Features
* Seamless integration with Django models
* Automatic generation of GraphQL schema
* Integration with Django's authentication and permission system
* Easy querying and filtering of data
* Support for Django's pagination system
* Compatible with Django's form and validation system
* Extensive documentation and community support
## Installation
To install Graphene-Django, run the following command:
```sh
pip install graphene-django
```
## Configuration
After installation, add 'graphene_django' to your Django project's `INSTALLED_APPS` list and define the GraphQL schema in your project's settings:
```python
INSTALLED_APPS = [
# ...
'graphene_django',
]
GRAPHENE = {
'SCHEMA': 'myapp.schema.schema'
}
```
## Usage
To use Graphene-Django, create a `schema.py` file in your Django app directory and define your GraphQL types and queries:
```python
import graphene
from graphene_django import DjangoObjectType
from .models import MyModel
class MyModelType(DjangoObjectType):
class Meta:
model = MyModel
class Query(graphene.ObjectType):
mymodels = graphene.List(MyModelType)
def resolve_mymodels(self, info, **kwargs):
return MyModel.objects.all()
schema = graphene.Schema(query=Query)
```
Then, expose the GraphQL API in your Django project's `urls.py` file:
```python
from django.urls import path
from graphene_django.views import GraphQLView
from . import schema
urlpatterns = [
# ...
path('graphql/', GraphQLView.as_view(graphiql=True)), # Given that schema path is defined in GRAPHENE['SCHEMA'] in your settings.py
]
```
## Testing
Graphene-Django provides support for testing GraphQL APIs using Django's test client. To create tests, create a `tests.py` file in your Django app directory and write your test cases:
```python
from django.test import TestCase
from graphene_django.utils.testing import GraphQLTestCase
from . import schema
class MyModelAPITestCase(GraphQLTestCase):
GRAPHENE_SCHEMA = schema.schema
def test_query_all_mymodels(self):
response = self.query(
'''
query {
mymodels {
id
name
}
}
'''
)
self.assertResponseNoErrors(response)
self.assertEqual(len(response.data['mymodels']), MyModel.objects.count())
```
## Contributing
Contributions to Graphene-Django are always welcome! To get started, check the repository's [issue tracker](https://github.com/graphql-python/graphene-django/issues) and [contribution guidelines](https://github.com/graphql-python/graphene-django/blob/main/CONTRIBUTING.md).
## License
Graphene-Django is released under the [MIT License](https://github.com/graphql-python/graphene-django/blob/main/LICENSE).
## Resources
* [Official GitHub Repository](https://github.com/graphql-python/graphene-django)
* [Graphene Documentation](http://docs.graphene-python.org/en/latest/)
* [Django Documentation](https://docs.djangoproject.com/en/stable/)
* [GraphQL Specification](https://spec.graphql.org/)
* [GraphiQL](https://github.com/graphql/graphiql) - An in-browser IDE for exploring GraphQL APIs
* [Graphene-Django Community](https://spectrum.chat/graphene) - Join the community to discuss questions and share ideas related to Graphene-Django
## Tutorials and Examples
* [Official Graphene-Django Tutorial](https://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/)
* [Building a GraphQL API with Django and Graphene-Django](https://www.howtographql.com/graphql-python/0-introduction/)
* [Real-world example: Django, Graphene, and Relay](https://github.com/graphql-python/swapi-graphene)
## Related Projects
* [Graphene](https://github.com/graphql-python/graphene) - A library for building GraphQL APIs in Python
* [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy) - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python
* [Graphene-File-Upload](https://github.com/lmcgartland/graphene-file-upload) - A package providing an Upload scalar for handling file uploads in Graphene
* [Graphene-Subscriptions](https://github.com/graphql-python/graphene-subscriptions) - A package for adding real-time subscriptions to Graphene-based GraphQL APIs
## Support
If you encounter any issues or have questions regarding Graphene-Django, feel free to [submit an issue](https://github.com/graphql-python/graphene-django/issues/new) on the official GitHub repository. You can also ask for help and share your experiences with the Graphene-Django community on [💬 Discord](https://discord.gg/Fftt273T79)
## Release Notes
* See [Releases page on github](https://github.com/graphql-python/graphene-django/releases)
Raw data
{
"_id": null,
"home_page": "https://github.com/graphql-python/graphene-django",
"name": "graphene-django",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "api graphql protocol rest relay graphene",
"author": "Syrus Akbary",
"author_email": "me@syrusakbary.com",
"download_url": "https://files.pythonhosted.org/packages/09/f1/4eb1c0ae79814aba03e2347f664cb0bef72816fbe99d4399378bb22bef47/graphene-django-3.2.2.tar.gz",
"platform": "any",
"description": "# ![Graphene Logo](http://graphene-python.org/favicon.png) Graphene-Django\n\n[![build][build-image]][build-url]\n[![pypi][pypi-image]][pypi-url]\n[![Anaconda-Server Badge][conda-image]][conda-url]\n[![coveralls][coveralls-image]][coveralls-url]\n\n[build-image]: https://github.com/graphql-python/graphene-django/workflows/Tests/badge.svg\n[build-url]: https://github.com/graphql-python/graphene-django/actions\n[pypi-image]: https://img.shields.io/pypi/v/graphene-django.svg?style=flat\n[pypi-url]: https://pypi.org/project/graphene-django/\n[coveralls-image]: https://coveralls.io/repos/github/graphql-python/graphene-django/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/github/graphql-python/graphene-django?branch=master\n[conda-image]: https://img.shields.io/conda/vn/conda-forge/graphene-django.svg\n[conda-url]: https://anaconda.org/conda-forge/graphene-django\n\nGraphene-Django is an open-source library that provides seamless integration between Django, a high-level Python web framework, and Graphene, a library for building GraphQL APIs. The library allows developers to create GraphQL APIs in Django quickly and efficiently while maintaining a high level of performance.\n\n## Features\n\n* Seamless integration with Django models\n* Automatic generation of GraphQL schema\n* Integration with Django's authentication and permission system\n* Easy querying and filtering of data\n* Support for Django's pagination system\n* Compatible with Django's form and validation system\n* Extensive documentation and community support\n\n## Installation\n\nTo install Graphene-Django, run the following command:\n\n```sh\npip install graphene-django\n```\n\n## Configuration\n\nAfter installation, add 'graphene_django' to your Django project's `INSTALLED_APPS` list and define the GraphQL schema in your project's settings:\n\n```python\nINSTALLED_APPS = [\n # ...\n 'graphene_django',\n]\n\nGRAPHENE = {\n 'SCHEMA': 'myapp.schema.schema'\n}\n```\n\n## Usage\n\nTo use Graphene-Django, create a `schema.py` file in your Django app directory and define your GraphQL types and queries:\n\n```python\nimport graphene\nfrom graphene_django import DjangoObjectType\nfrom .models import MyModel\n\nclass MyModelType(DjangoObjectType):\n class Meta:\n model = MyModel\n\nclass Query(graphene.ObjectType):\n mymodels = graphene.List(MyModelType)\n\n def resolve_mymodels(self, info, **kwargs):\n return MyModel.objects.all()\n\nschema = graphene.Schema(query=Query)\n```\n\nThen, expose the GraphQL API in your Django project's `urls.py` file:\n\n```python\nfrom django.urls import path\nfrom graphene_django.views import GraphQLView\nfrom . import schema\n\nurlpatterns = [\n # ...\n path('graphql/', GraphQLView.as_view(graphiql=True)), # Given that schema path is defined in GRAPHENE['SCHEMA'] in your settings.py\n]\n```\n\n## Testing\n\nGraphene-Django provides support for testing GraphQL APIs using Django's test client. To create tests, create a `tests.py` file in your Django app directory and write your test cases:\n\n```python\nfrom django.test import TestCase\nfrom graphene_django.utils.testing import GraphQLTestCase\nfrom . import schema\n\nclass MyModelAPITestCase(GraphQLTestCase):\n GRAPHENE_SCHEMA = schema.schema\n\n def test_query_all_mymodels(self):\n response = self.query(\n '''\n query {\n mymodels {\n id\n name\n }\n }\n '''\n )\n\n self.assertResponseNoErrors(response)\n self.assertEqual(len(response.data['mymodels']), MyModel.objects.count())\n```\n\n## Contributing\n\nContributions to Graphene-Django are always welcome! To get started, check the repository's [issue tracker](https://github.com/graphql-python/graphene-django/issues) and [contribution guidelines](https://github.com/graphql-python/graphene-django/blob/main/CONTRIBUTING.md).\n\n## License\n\nGraphene-Django is released under the [MIT License](https://github.com/graphql-python/graphene-django/blob/main/LICENSE).\n\n## Resources\n\n* [Official GitHub Repository](https://github.com/graphql-python/graphene-django)\n* [Graphene Documentation](http://docs.graphene-python.org/en/latest/)\n* [Django Documentation](https://docs.djangoproject.com/en/stable/)\n* [GraphQL Specification](https://spec.graphql.org/)\n* [GraphiQL](https://github.com/graphql/graphiql) - An in-browser IDE for exploring GraphQL APIs\n* [Graphene-Django Community](https://spectrum.chat/graphene) - Join the community to discuss questions and share ideas related to Graphene-Django\n\n## Tutorials and Examples\n\n* [Official Graphene-Django Tutorial](https://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/)\n* [Building a GraphQL API with Django and Graphene-Django](https://www.howtographql.com/graphql-python/0-introduction/)\n* [Real-world example: Django, Graphene, and Relay](https://github.com/graphql-python/swapi-graphene)\n\n## Related Projects\n\n* [Graphene](https://github.com/graphql-python/graphene) - A library for building GraphQL APIs in Python\n* [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy) - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python\n* [Graphene-File-Upload](https://github.com/lmcgartland/graphene-file-upload) - A package providing an Upload scalar for handling file uploads in Graphene\n* [Graphene-Subscriptions](https://github.com/graphql-python/graphene-subscriptions) - A package for adding real-time subscriptions to Graphene-based GraphQL APIs\n\n## Support\n\nIf you encounter any issues or have questions regarding Graphene-Django, feel free to [submit an issue](https://github.com/graphql-python/graphene-django/issues/new) on the official GitHub repository. You can also ask for help and share your experiences with the Graphene-Django community on [\ud83d\udcac Discord](https://discord.gg/Fftt273T79)\n\n## Release Notes\n\n* See [Releases page on github](https://github.com/graphql-python/graphene-django/releases)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Graphene Django integration",
"version": "3.2.2",
"project_urls": {
"Homepage": "https://github.com/graphql-python/graphene-django"
},
"split_keywords": [
"api",
"graphql",
"protocol",
"rest",
"relay",
"graphene"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "da716800d05144ee4fb57f471571dd80fc9c6b2196e6243d39ed3d3654082824",
"md5": "33f198b8d2aaab193b3a3c6ee78d2f49",
"sha256": "0fd95c8c1cbe77ae2a5940045ce276803c3acbf200a156731e0c730f2776ae2c"
},
"downloads": -1,
"filename": "graphene_django-3.2.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "33f198b8d2aaab193b3a3c6ee78d2f49",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 114204,
"upload_time": "2024-06-12T02:58:07",
"upload_time_iso_8601": "2024-06-12T02:58:07.897145Z",
"url": "https://files.pythonhosted.org/packages/da/71/6800d05144ee4fb57f471571dd80fc9c6b2196e6243d39ed3d3654082824/graphene_django-3.2.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "09f14eb1c0ae79814aba03e2347f664cb0bef72816fbe99d4399378bb22bef47",
"md5": "5fb7af3e81cb1a21e6f2b7c2a7cb6af7",
"sha256": "059ccf25d9a5159f28d7ebf1a648c993ab34deb064e80b70ca096aa22a609556"
},
"downloads": -1,
"filename": "graphene-django-3.2.2.tar.gz",
"has_sig": false,
"md5_digest": "5fb7af3e81cb1a21e6f2b7c2a7cb6af7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 87591,
"upload_time": "2024-06-12T02:58:09",
"upload_time_iso_8601": "2024-06-12T02:58:09.439513Z",
"url": "https://files.pythonhosted.org/packages/09/f1/4eb1c0ae79814aba03e2347f664cb0bef72816fbe99d4399378bb22bef47/graphene-django-3.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-12 02:58:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "graphql-python",
"github_project": "graphene-django",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "graphene-django"
}