Skip to content

Commit 202de3f

Browse files
docs: add tutorial
* Restructure get-started section * Add server example to executors
1 parent dc4d410 commit 202de3f

File tree

8 files changed

+134
-218
lines changed

8 files changed

+134
-218
lines changed

docs/development/overview.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Build on top of garf
22

3-
You can create on top of `garf` you can have a couple of options:
3+
While `garf` provides you with a lot of built-in functionality it might not be
4+
sufficient for an API of your choice.
45

5-
* [Create an API client](create-api-client.md) to be used with `ApiReportFetcher` class
6-
* [Create an API response parser](create-api-response-parser.md) to be customize how `ApiReportFetcher` parses response from API
6+
To make `garf` work with your API explore options below:
7+
8+
* [Create an API client](create-api-client.md) to be used with `ApiReportFetcher` class.
9+
* [Create an API response parser](create-api-response-parser.md) to be customize how `ApiReportFetcher` parses response from API.
710
* [Create a library](create-garf-library.md) and expose it as `garf` plugin.

docs/get-started/cli.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

docs/get-started/index.md

Lines changed: 95 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,97 @@
11
# Overview
22

3-
`garf` can be used in a multiple ways.
4-
5-
<div class="grid cards" markdown>
6-
7-
- :material-console-line: **Installation**
8-
9-
----
10-
11-
Install `garf-executors` to run queries against APIs.
12-
13-
[:octicons-arrow-right-24: More information](installation.md)
14-
15-
- :simple-python: **Library**
16-
17-
----
18-
19-
Integrate `garf` into your libraries.
20-
21-
[:octicons-arrow-right-24: More information](library.md)
22-
23-
- :material-console-line: **CLI**
24-
25-
----
26-
27-
Execute queries in your terminal.
28-
29-
[:octicons-arrow-right-24: More information](cli.md)
30-
31-
- :simple-fastapi: **Server**
32-
33-
----
34-
35-
Run `garf` as FastAPI endpoint.
36-
37-
[:octicons-arrow-right-24: More information](server.md)
38-
</div>
3+
Let's use `garf` to query [https://restful-api.dev](https://restful-api.dev) (publicly available API) and save results to BigQuery.
4+
5+
## Installation
6+
7+
/// tab | pip
8+
```
9+
pip install garf-executors
10+
```
11+
///
12+
13+
/// tab | uv
14+
```
15+
uv add garf-executors
16+
```
17+
///
18+
19+
## Create query
20+
21+
[https://restful-api.dev](https://restful-api.dev) has ` https://api.restful-api.dev/objects` endpoint to get list of objects in the following format:
22+
23+
```json
24+
[
25+
{
26+
"id": "1",
27+
"name": "Google Pixel 6 Pro",
28+
"data": {
29+
"color": "Cloudy White",
30+
"capacity": "128 GB"
31+
}
32+
},
33+
{
34+
"id": "2",
35+
"name": "Apple iPhone 12 Mini, 256GB, Blue",
36+
"data": null
37+
},
38+
{
39+
"id": "3",
40+
"name": "Apple iPhone 12 Pro Max",
41+
"data": {
42+
"color": "Cloudy White",
43+
"capacity GB": 512
44+
}
45+
}
46+
]
47+
```
48+
49+
Support we want to get `id`, `name` and `color` of each device.
50+
51+
Let's create a query to get this information.
52+
53+
```sql
54+
SELECT
55+
id AS device_id,
56+
name AS device_name,
57+
data.color AS device_color
58+
FROM objects
59+
```
60+
61+
We can save this query to a local file called `devices.sql`.
62+
63+
```bash
64+
echo "
65+
SELECT
66+
id AS device_id,
67+
name AS device_name,
68+
data.color AS device_color
69+
FROM objects" > devices.sql
70+
```
71+
72+
## Execute query
73+
74+
Since the API we're working with is of REST type we can use `garf`'s built-in `rest` source and provide API address to get data from.
75+
76+
We'll use `garf` CLI tool get the data. The only thing we need to specify is root endpoint where API is located (`https://api.restful-api.dev` in our case).
77+
78+
```bash
79+
garf devices.sql --source rest \
80+
--source.endpoint=https://api.restful-api.dev \
81+
--output bq
82+
```
83+
84+
!!! note
85+
Since we want to write data to BigQuery we specified `bq` output type.
86+
By default results will be stored in default project (`GOOGLE_CLOUD_PROJECT`) in `garf` dataset under name `devices`.
87+
88+
## Next steps
89+
90+
Congratulations, you executed your first query with `garf`!
91+
92+
Now you can explore various options `garf` provides:
93+
94+
* **How to write queries**: Learn an extensive [SQL syntax](../usage/queries.md) capabilities `garf` supports.
95+
* **How to use garf in your Python projects**: `garf` makes it easy to [fetch data](../usage/fetcher.md) and works with fetched [reports](../usage/reports.md).
96+
* **Supported writers**: Learn where you can [write data](../usage/writers.md) fetched from your APIs.
97+
* **Executors**: Learn how to process multiple queries with [executors](../usage/executors.md).

docs/get-started/installation.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

docs/get-started/library.md

Lines changed: 0 additions & 73 deletions
This file was deleted.

docs/get-started/server.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

docs/usage/executors.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ pip install garf-executors[sql]
3131
```
3232
///
3333

34+
/// tab | server
35+
```bash
36+
pip install garf-executors[server]
37+
```
38+
///
39+
3440
## Usage
3541

3642
After `garf-executors` is installed you can use `garf` utility to perform fetching.
@@ -70,6 +76,31 @@ query_executor.execute(
7076
```
7177
///
7278

79+
/// tab | server
80+
81+
!!!note
82+
Ensure that API endpoint for `garf` is running.
83+
```bash
84+
python garf_executors.entrypoints.server
85+
```
86+
87+
```bash
88+
curl -X 'POST' \
89+
'http://127.0.0.1:8000/api/execute' \
90+
-H 'accept: application/json' \
91+
-H 'Content-Type: application/json' \
92+
-d '{
93+
"source": "API_SOURCE",
94+
"title": "query",
95+
"query": "YOUR_QUERY_HERE",
96+
"context": {
97+
"writer": "OUTPUT_TYPE"
98+
}
99+
}'
100+
```
101+
102+
///
103+
73104
## Customization
74105

75106
### Source
@@ -117,6 +148,7 @@ query_executor.execute(
117148
context=context
118149
)
119150
```
151+
///
120152

121153
### Macro
122154

mkdocs.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,7 @@ markdown_extensions:
5252

5353
nav:
5454
- Home: index.md
55-
- Get Started:
56-
- get-started/index.md
57-
- Installation: get-started/installation.md
58-
- Quickstart:
59-
- Library: get-started/library.md
60-
- CLI: get-started/cli.md
61-
- Server: get-started/server.md
55+
- Tutorial: get-started/index.md
6256
- Usage:
6357
- Core:
6458
- usage/core.md

0 commit comments

Comments
 (0)