<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/98/47/a784b6513feca8020897cb75ad9df01e379917950d2a7925faaca535fdaf/strawberry_graphql-0.252.0.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.252.0",
"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": "0cf46d1cfe46d09d076e03e7420a41b37f960f9c8814f52964d9dbf977cc4f8f",
"md5": "2b10033e70a64d26f7b95438afc3c7d2",
"sha256": "0703da4ccc5261a92e19ed13e2e8c81da06361296b35e26a5363e6edbbc0344e"
},
"downloads": -1,
"filename": "strawberry_graphql-0.252.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2b10033e70a64d26f7b95438afc3c7d2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 295336,
"upload_time": "2024-11-22T11:40:48",
"upload_time_iso_8601": "2024-11-22T11:40:48.766247Z",
"url": "https://files.pythonhosted.org/packages/0c/f4/6d1cfe46d09d076e03e7420a41b37f960f9c8814f52964d9dbf977cc4f8f/strawberry_graphql-0.252.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9847a784b6513feca8020897cb75ad9df01e379917950d2a7925faaca535fdaf",
"md5": "dc8596f0e4737209ccc861053969b7a7",
"sha256": "b5275b34f99e2adc1474abe1c13681cacc89cff56d02994572f3f0667c1c6106"
},
"downloads": -1,
"filename": "strawberry_graphql-0.252.0.tar.gz",
"has_sig": false,
"md5_digest": "dc8596f0e4737209ccc861053969b7a7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 207910,
"upload_time": "2024-11-22T11:40:51",
"upload_time_iso_8601": "2024-11-22T11:40:51.367020Z",
"url": "https://files.pythonhosted.org/packages/98/47/a784b6513feca8020897cb75ad9df01e379917950d2a7925faaca535fdaf/strawberry_graphql-0.252.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-22 11:40:51",
"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"
}