<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
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.
![Recent Activity](https://images.repography.com/0/strawberry-graphql/strawberry/recent-activity/d751713988987e9331980363e24189ce.svg)
Raw data
{
"_id": null,
"home_page": "https://strawberry.rocks/",
"name": "564bff00ff-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/8a/884e4c129559473dcb23ae9eb18907c89f61373b4f11df8b42db8ff9a4d0/564bff00ff_strawberry_graphql-0.168.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\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![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.168.2",
"split_keywords": [
"graphql",
"api",
"rest",
"starlette",
"async"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3024e35428c8613d59617d038a56573e33808414317f3ca26ec8dd1c1b0bbcb3",
"md5": "6f24ec4a95fb88e40215313625d00f8a",
"sha256": "0e12dc3fa0f81b72260033aba2b8896cd64c95ae27460adbef50f7f734c51ede"
},
"downloads": -1,
"filename": "564bff00ff_strawberry_graphql-0.168.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6f24ec4a95fb88e40215313625d00f8a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 235943,
"upload_time": "2023-03-27T13:22:48",
"upload_time_iso_8601": "2023-03-27T13:22:48.633975Z",
"url": "https://files.pythonhosted.org/packages/30/24/e35428c8613d59617d038a56573e33808414317f3ca26ec8dd1c1b0bbcb3/564bff00ff_strawberry_graphql-0.168.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "408a884e4c129559473dcb23ae9eb18907c89f61373b4f11df8b42db8ff9a4d0",
"md5": "14d619aa781b0c87eddb0574d4504e2c",
"sha256": "4623a9a304726310ac6be336c13d65f6fbed319cc6bb5f5a12a69531b6e7c0e5"
},
"downloads": -1,
"filename": "564bff00ff_strawberry_graphql-0.168.2.tar.gz",
"has_sig": false,
"md5_digest": "14d619aa781b0c87eddb0574d4504e2c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 163125,
"upload_time": "2023-03-27T13:22:50",
"upload_time_iso_8601": "2023-03-27T13:22:50.221839Z",
"url": "https://files.pythonhosted.org/packages/40/8a/884e4c129559473dcb23ae9eb18907c89f61373b4f11df8b42db8ff9a4d0/564bff00ff_strawberry_graphql-0.168.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-27 13:22:50",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "564bff00ff-strawberry-graphql"
}