<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
[](https://circleci.com/gh/strawberry-graphql/strawberry/tree/main)
[](https://discord.gg/ZkRTEJQ)
[](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
poetry run pytest
```
This will install all the dependencies (including dev ones) and run the tests.
### 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.

Raw data
{
"_id": null,
"home_page": "https://strawberry.rocks/",
"name": "strawberry-graphql",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "graphql,api,rest,starlette,async",
"author": "Patrick Arminio",
"author_email": "patrick.arminio@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/40/92/4f96684487f4d6a0c982dc41de3699ef339a88f0b3f0fc7a7c3d29a6dcc4/strawberry_graphql-0.180.5.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[](https://circleci.com/gh/strawberry-graphql/strawberry/tree/main)\n[](https://discord.gg/ZkRTEJQ)\n[](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\npoetry run pytest\n```\n\nThis will install all the dependencies (including dev ones) and run the tests.\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\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library for creating GraphQL APIs",
"version": "0.180.5",
"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": "81a6f5eb108f73ba36ddfb370f61a92844464d3121426775e117136a02139b28",
"md5": "1dc5076d1849e39c3aec5f427a6ebcfb",
"sha256": "f08c4445711205d9bb12fd59cba7631e754efe93fe08ec5b7a7d7f2ee60750fa"
},
"downloads": -1,
"filename": "strawberry_graphql-0.180.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1dc5076d1849e39c3aec5f427a6ebcfb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 243317,
"upload_time": "2023-06-02T18:23:21",
"upload_time_iso_8601": "2023-06-02T18:23:21.084524Z",
"url": "https://files.pythonhosted.org/packages/81/a6/f5eb108f73ba36ddfb370f61a92844464d3121426775e117136a02139b28/strawberry_graphql-0.180.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "40924f96684487f4d6a0c982dc41de3699ef339a88f0b3f0fc7a7c3d29a6dcc4",
"md5": "a5d3483c011996f886861583c5bfda92",
"sha256": "3ef3e4a3d82f69c7da8436ca36504414230c83063e46a967df8eb5645121b6b5"
},
"downloads": -1,
"filename": "strawberry_graphql-0.180.5.tar.gz",
"has_sig": false,
"md5_digest": "a5d3483c011996f886861583c5bfda92",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 164789,
"upload_time": "2023-06-02T18:23:23",
"upload_time_iso_8601": "2023-06-02T18:23:23.769183Z",
"url": "https://files.pythonhosted.org/packages/40/92/4f96684487f4d6a0c982dc41de3699ef339a88f0b3f0fc7a7c3d29a6dcc4/strawberry_graphql-0.180.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-02 18:23:23",
"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"
}