Skip to content

Commit 4ae01e5

Browse files
authored
Merge pull request graphql#1203 from qlient-org/patch-1
Add qlient as a python client.
2 parents 96d1f46 + d232527 commit 4ae01e5

File tree

1 file changed

+40
-0
lines changed
  • src/content/code/language-support/python/client

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: Qlient
3+
description: A fast and modern graphql client designed with simplicity in mind.
4+
url: https://github.com/qlient-org/python-qlient
5+
github: qlient-org/python-qlient
6+
---
7+
8+
Here's an example of a qlient hello world.
9+
10+
first install the library:
11+
12+
```bash
13+
pip install qlient
14+
```
15+
16+
Create a `swapi_client_example.py` file with this content:
17+
18+
```python
19+
from qlient import Client, GraphQLResponse
20+
21+
client = Client("https://swapi-graphql.netlify.app/.netlify/functions/index")
22+
23+
res: GraphQLResponse = client.query.film(
24+
# swapi graphql input fields
25+
id="ZmlsbXM6MQ==",
26+
27+
# qlient specific
28+
_fields=["id", "title", "episodeID"]
29+
)
30+
31+
print(res.query) # query film($id: ID) { film(id: $id) { id title episodeID } }
32+
print(res.variables) # {'id': 'ZmlsbXM6MQ=='}
33+
print(res.data) # {'film': {'id': 'ZmlsbXM6MQ==', 'title': 'A New Hope', 'episodeID': 4}}
34+
```
35+
36+
Close the file and run it using python:
37+
38+
```bash
39+
python swapi_client_example.py
40+
```

0 commit comments

Comments
 (0)