<img src="https://github.com/strawberry-graphql/strawberry/raw/main/.github/logo.png" width="124" height="150">
# Strawberry GraphQL
> Python GraphQL library based on dataclasses
[![CircleCI](https://img.shields.io/circleci/token/307b40d5e152e074d34f84d30d226376a15667d5/project/github/strawberry-graphql/strawberry/main.svg?style=for-the-badge)](https://circleci.com/gh/strawberry-graphql/strawberry/tree/main)
[![Discord](https://img.shields.io/discord/689806334337482765?label=discord&logo=discord&logoColor=white&style=for-the-badge&color=blue)](https://discord.gg/ZkRTEJQ)
[![PyPI](https://img.shields.io/pypi/v/strawberry-graphql?logo=pypi&logoColor=white&style=for-the-badge)](https://pypi.org/project/strawberry-graphql/)
## Installation ( Quick Start )
The quick start method provides a server and CLI to get going quickly. Install
with:
```shell
pip install "strawberry-graphql[debug-server]"
```
## Getting Started
Create a file called `app.py` with the following code:
```python
import strawberry
@strawberry.type
class User:
name: str
age: int
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return User(name="Patrick", age=100)
schema = strawberry.Schema(query=Query)
```
This will create a GraphQL schema defining a `User` type and a single query
field `user` that will return a hardcoded user.
To run the debug server run the following command:
```shell
strawberry server app
```
Open the debug server by clicking on the following link:
[http://0.0.0.0:8000/graphql](http://0.0.0.0:8000/graphql)
This will open GraphiQL where you can test the API.
### Type-checking
Strawberry comes with a [mypy] plugin that enables statically type-checking your
GraphQL schema. To enable it, add the following lines to your `mypy.ini`
configuration:
```ini
[mypy]
plugins = strawberry.ext.mypy_plugin
```
[mypy]: http://www.mypy-lang.org/
### Django Integration
A Django view is provided for adding a GraphQL endpoint to your application.
1. Add the app to your `INSTALLED_APPS`.
```python
INSTALLED_APPS = [
..., # your other apps
"strawberry.django",
]
```
2. Add the view to your `urls.py` file.
```python
from strawberry.django.views import GraphQLView
from .schema import schema
urlpatterns = [
...,
path("graphql", GraphQLView.as_view(schema=schema)),
]
```
## WebSockets
To support graphql Subscriptions over WebSockets you need to provide a WebSocket
enabled server. The debug server can be made to support WebSockets with these
commands:
```shell
pip install 'strawberry-graphql[debug-server]'
pip install 'uvicorn[standard]'
```
## Examples
* [Various examples on how to use Strawberry](https://github.com/strawberry-graphql/examples)
* [Full stack example using Starlette, SQLAlchemy, Typescript codegen and Next.js](https://github.com/jokull/python-ts-graphql-demo)
* [Quart + Strawberry tutorial](https://github.com/rockyburt/Ketchup)
## Contributing
We use [poetry](https://github.com/sdispater/poetry) to manage dependencies, to
get started follow these steps:
```shell
git clone https://github.com/strawberry-graphql/strawberry
cd strawberry
poetry install --with integrations
poetry run pytest
```
For all further detail, check out the [Contributing Page](CONTRIBUTING.md)
### Pre commit
We have a configuration for
[pre-commit](https://github.com/pre-commit/pre-commit), to add the hook run the
following command:
```shell
pre-commit install
```
## Links
- Project homepage: https://strawberry.rocks
- Repository: https://github.com/strawberry-graphql/strawberry
- Issue tracker: https://github.com/strawberry-graphql/strawberry/issues
- In case of sensitive bugs like security vulnerabilities, please contact
patrick.arminio@gmail.com directly instead of using the issue tracker. We
value your effort to improve the security and privacy of this project!
## Licensing
The code in this project is licensed under MIT license. See [LICENSE](./LICENSE)
for more information.
![Recent Activity](https://images.repography.com/0/strawberry-graphql/strawberry/recent-activity/d751713988987e9331980363e24189ce.svg)
Raw data
{
"_id": null,
"home_page": "https://strawberry.rocks/",
"name": "strawberry-graphql",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "graphql, api, rest, starlette, async",
"author": "Patrick Arminio",
"author_email": "patrick.arminio@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b2/b0/a7d6095bff69858f961b3cb6619588aeabe483348b2cffe889bd30209953/strawberry_graphql-0.227.2.tar.gz",
"platform": null,
"description": "<img src=\"https://github.com/strawberry-graphql/strawberry/raw/main/.github/logo.png\" width=\"124\" height=\"150\">\n\n# Strawberry GraphQL\n\n> Python GraphQL library based on dataclasses\n\n[![CircleCI](https://img.shields.io/circleci/token/307b40d5e152e074d34f84d30d226376a15667d5/project/github/strawberry-graphql/strawberry/main.svg?style=for-the-badge)](https://circleci.com/gh/strawberry-graphql/strawberry/tree/main)\n[![Discord](https://img.shields.io/discord/689806334337482765?label=discord&logo=discord&logoColor=white&style=for-the-badge&color=blue)](https://discord.gg/ZkRTEJQ)\n[![PyPI](https://img.shields.io/pypi/v/strawberry-graphql?logo=pypi&logoColor=white&style=for-the-badge)](https://pypi.org/project/strawberry-graphql/)\n\n## Installation ( Quick Start )\n\nThe quick start method provides a server and CLI to get going quickly. Install\nwith:\n\n```shell\npip install \"strawberry-graphql[debug-server]\"\n```\n\n## Getting Started\n\nCreate a file called `app.py` with the following code:\n\n```python\nimport strawberry\n\n\n@strawberry.type\nclass User:\n name: str\n age: int\n\n\n@strawberry.type\nclass Query:\n @strawberry.field\n def user(self) -> User:\n return User(name=\"Patrick\", age=100)\n\n\nschema = strawberry.Schema(query=Query)\n```\n\nThis will create a GraphQL schema defining a `User` type and a single query\nfield `user` that will return a hardcoded user.\n\nTo run the debug server run the following command:\n\n```shell\nstrawberry server app\n```\n\nOpen the debug server by clicking on the following link:\n[http://0.0.0.0:8000/graphql](http://0.0.0.0:8000/graphql)\n\nThis will open GraphiQL where you can test the API.\n\n### Type-checking\n\nStrawberry comes with a [mypy] plugin that enables statically type-checking your\nGraphQL schema. To enable it, add the following lines to your `mypy.ini`\nconfiguration:\n\n```ini\n[mypy]\nplugins = strawberry.ext.mypy_plugin\n```\n\n[mypy]: http://www.mypy-lang.org/\n\n### Django Integration\n\nA Django view is provided for adding a GraphQL endpoint to your application.\n\n1. Add the app to your `INSTALLED_APPS`.\n\n```python\nINSTALLED_APPS = [\n ..., # your other apps\n \"strawberry.django\",\n]\n```\n\n2. Add the view to your `urls.py` file.\n\n```python\nfrom strawberry.django.views import GraphQLView\nfrom .schema import schema\n\nurlpatterns = [\n ...,\n path(\"graphql\", GraphQLView.as_view(schema=schema)),\n]\n```\n\n## WebSockets\n\nTo support graphql Subscriptions over WebSockets you need to provide a WebSocket\nenabled server. The debug server can be made to support WebSockets with these\ncommands:\n\n```shell\npip install 'strawberry-graphql[debug-server]'\npip install 'uvicorn[standard]'\n```\n\n## Examples\n\n* [Various examples on how to use Strawberry](https://github.com/strawberry-graphql/examples)\n* [Full stack example using Starlette, SQLAlchemy, Typescript codegen and Next.js](https://github.com/jokull/python-ts-graphql-demo)\n* [Quart + Strawberry tutorial](https://github.com/rockyburt/Ketchup)\n\n## Contributing\n\nWe use [poetry](https://github.com/sdispater/poetry) to manage dependencies, to\nget started follow these steps:\n\n```shell\ngit clone https://github.com/strawberry-graphql/strawberry\ncd strawberry\npoetry install --with integrations\npoetry run pytest\n```\n\nFor all further detail, check out the [Contributing Page](CONTRIBUTING.md)\n\n\n### Pre commit\n\nWe have a configuration for\n[pre-commit](https://github.com/pre-commit/pre-commit), to add the hook run the\nfollowing command:\n\n```shell\npre-commit install\n```\n\n## Links\n\n- Project homepage: https://strawberry.rocks\n- Repository: https://github.com/strawberry-graphql/strawberry\n- Issue tracker: https://github.com/strawberry-graphql/strawberry/issues\n - In case of sensitive bugs like security vulnerabilities, please contact\n patrick.arminio@gmail.com directly instead of using the issue tracker. We\n value your effort to improve the security and privacy of this project!\n\n## Licensing\n\nThe code in this project is licensed under MIT license. See [LICENSE](./LICENSE)\nfor more information.\n\n![Recent Activity](https://images.repography.com/0/strawberry-graphql/strawberry/recent-activity/d751713988987e9331980363e24189ce.svg)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library for creating GraphQL APIs",
"version": "0.227.2",
"project_urls": {
"Changelog": "https://strawberry.rocks/changelog",
"Discord": "https://discord.com/invite/3uQ2PaY",
"Documentation": "https://strawberry.rocks/",
"Homepage": "https://strawberry.rocks/",
"Mastodon": "https://farbun.social/@strawberry",
"Repository": "https://github.com/strawberry-graphql/strawberry",
"Sponsor on GitHub": "https://github.com/sponsors/strawberry-graphql",
"Sponsor on Open Collective": "https://opencollective.com/strawberry-graphql",
"Twitter": "https://twitter.com/strawberry_gql"
},
"split_keywords": [
"graphql",
" api",
" rest",
" starlette",
" async"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2f672c8a9ffd286aed48ecd062c1ca8c247ed7f2525402b43bdc1e981c2f751e",
"md5": "2a15169ec797bf4347cc56efaf84760c",
"sha256": "f03ecdd75ff8855be5dbd87f552a7f9a2f7891b0c1054b6f7c22a934523964c8"
},
"downloads": -1,
"filename": "strawberry_graphql-0.227.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2a15169ec797bf4347cc56efaf84760c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 290045,
"upload_time": "2024-04-21T15:32:46",
"upload_time_iso_8601": "2024-04-21T15:32:46.021672Z",
"url": "https://files.pythonhosted.org/packages/2f/67/2c8a9ffd286aed48ecd062c1ca8c247ed7f2525402b43bdc1e981c2f751e/strawberry_graphql-0.227.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b2b0a7d6095bff69858f961b3cb6619588aeabe483348b2cffe889bd30209953",
"md5": "ea2099c1b4752c0be771ba8a8cd72f74",
"sha256": "c65ddc1d3c6b9dac9987360261920f2938fdab84260074d5f677a7272a75c9b5"
},
"downloads": -1,
"filename": "strawberry_graphql-0.227.2.tar.gz",
"has_sig": false,
"md5_digest": "ea2099c1b4752c0be771ba8a8cd72f74",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 199059,
"upload_time": "2024-04-21T15:32:53",
"upload_time_iso_8601": "2024-04-21T15:32:53.905116Z",
"url": "https://files.pythonhosted.org/packages/b2/b0/a7d6095bff69858f961b3cb6619588aeabe483348b2cffe889bd30209953/strawberry_graphql-0.227.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-21 15:32:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "strawberry-graphql",
"github_project": "strawberry",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "strawberry-graphql"
}