Skip to content

Commit ce36e6b

Browse files
docs: extract concrect writers info into dedicated sections
1 parent 35c442d commit ce36e6b

File tree

8 files changed

+418
-421
lines changed

8 files changed

+418
-421
lines changed

docs/usage/bq-writer.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
!!! important
2+
To save data to BigQuery install `garf-io` with BigQuery support
3+
4+
```bash
5+
pip install garf-io[bq]
6+
```
7+
8+
9+
`bq` writer allows you to save `GarfReport` to BigQuery table.
10+
11+
/// tab | cli
12+
```bash
13+
garf query.sql --source API_SOURCE \
14+
--output bq
15+
```
16+
///
17+
18+
/// tab | python
19+
```python
20+
from garf_core import report
21+
from garf_io.writers import bigquery_writer
22+
23+
# Create example report
24+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
25+
26+
writer = bigquery_writer.BigQueryWriter()
27+
writer.write(sample_report, 'query')
28+
```
29+
///
30+
31+
## Parameters
32+
### Project
33+
34+
By default reports are saved to `GOOGLE_CLOUD_PROJECT`.
35+
You can overwrite it with `project` parameter.
36+
37+
/// tab | cli
38+
```bash hl_lines="3"
39+
garf query.sql --source API_SOURCE \
40+
--output bq \
41+
--bq.project=PROJECT_ID
42+
```
43+
///
44+
45+
/// tab | python
46+
```python hl_lines="7"
47+
from garf_core import report
48+
from garf_io.writers import bigquery_writer
49+
50+
# Create example report
51+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
52+
53+
writer = bigquery_writer.BigQueryWriter(project="PROJECT_ID")
54+
writer.write(sample_report, 'query')
55+
```
56+
///
57+
58+
### Dataset
59+
60+
By default reports are saved to `garf` dataset.
61+
You can overwrite it with `dataset` parameter.
62+
63+
/// tab | cli
64+
```bash hl_lines="3"
65+
garf query.sql --source API_SOURCE \
66+
--output bq \
67+
--bq.dataset=DATASET
68+
```
69+
///
70+
71+
/// tab | python
72+
```python hl_lines="7"
73+
from garf_core import report
74+
from garf_io.writers import bigquery_writer
75+
76+
# Create example report
77+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
78+
79+
writer = bigquery_writer.BigQueryWriter(dataset="DATASET")
80+
writer.write(sample_report, 'query')
81+
```
82+
///
83+
84+
### Location
85+
86+
By default reports are saved to `US` location.
87+
You can overwrite it with `location` parameter.
88+
89+
/// tab | cli
90+
```bash hl_lines="3"
91+
garf query.sql --source API_SOURCE \
92+
--output bq \
93+
--bq.location=LOCATION
94+
```
95+
///
96+
97+
/// tab | python
98+
```python hl_lines="7"
99+
from garf_core import report
100+
from garf_io.writers import bigquery_writer
101+
102+
# Create example report
103+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
104+
105+
writer = bigquery_writer.BigQueryWriter(location="LOCATION")
106+
writer.write(sample_report, 'query')
107+
```
108+
///
109+
110+
### Write disposition
111+
112+
By default reports overwrite any existing data.
113+
You can overwrite it with [`write_disposition`](https://cloud.google.com/bigquery/docs/reference/auditlogs/rest/Shared.Types/BigQueryAuditMetadata.WriteDisposition) parameter.
114+
115+
/// tab | cli
116+
```bash hl_lines="3"
117+
garf query.sql --source API_SOURCE \
118+
--output bq \
119+
--bq.write_disposition=DISPOSITION
120+
```
121+
///
122+
123+
/// tab | python
124+
```python hl_lines="7"
125+
from garf_core import report
126+
from garf_io.writers import bigquery_writer
127+
128+
# Create example report
129+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
130+
131+
writer = bigquery_writer.BigQueryWriter(write_disposition="DISPOSITION")
132+
writer.write(sample_report, 'query')
133+
```
134+
///

docs/usage/console-writer.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
`console` writer allows you to print `GarfReport` to standard output in the terminal.
2+
3+
/// tab | cli
4+
```bash
5+
garf query.sql --source API_SOURCE \
6+
--output console
7+
```
8+
///
9+
10+
/// tab | python
11+
```python
12+
from garf_core import report
13+
from garf_io.writers import console_writer
14+
15+
# Create example report
16+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
17+
18+
writer = console_writer.ConsoleWriter()
19+
writer.write(sample_report, 'query')
20+
```
21+
///
22+
23+
##Parameters
24+
25+
### Format
26+
27+
For `console` writer you can specify the output format:
28+
29+
* `table` - rich table (default).
30+
* `json` - JSON.
31+
* `jsonl` - JSON lines
32+
33+
/// tab | cli
34+
```bash hl_lines="3"
35+
garf query.sql --source API_SOURCE \
36+
--output console \
37+
--console.format=json
38+
```
39+
///
40+
41+
/// tab | python
42+
```python hl_lines="7"
43+
from garf_core import report
44+
from garf_io.writers import console_writer
45+
46+
# Create example report
47+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
48+
49+
writer = console_writer.ConsoleWriter(format='json')
50+
writer.write(sample_report, 'query')
51+
```
52+
///
53+
54+
### Page size
55+
56+
If you're using `console` writer with `table` format option, you can specify
57+
`page_size` parameter to print N rows to the console.
58+
59+
/// tab | cli
60+
```bash hl_lines="3"
61+
garf query.sql --source API_SOURCE \
62+
--output console \
63+
--console.page-size=100
64+
```
65+
///
66+
67+
/// tab | python
68+
```python hl_lines="7"
69+
from garf_core import report
70+
from garf_io.writers import console_writer
71+
72+
# Create example report
73+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
74+
75+
writer = console_writer.ConsoleWriter(page_size=100)
76+
writer.write(sample_report, 'query')
77+
```
78+
///

docs/usage/csv-writer.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
`csv` writer allows you to save `GarfReport` as a CSV file to local or remote storage.
2+
3+
/// tab | cli
4+
```bash
5+
garf query.sql --source API_SOURCE \
6+
--output csv
7+
```
8+
///
9+
10+
/// tab | python
11+
```python
12+
from garf_core import report
13+
from garf_io.writers import csv_writer
14+
15+
# Create example report
16+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
17+
18+
writer = csv_writer.CsvWriter()
19+
writer.write(sample_report, 'query')
20+
```
21+
///
22+
23+
## Parameters
24+
25+
### Destination folder
26+
27+
For `csv` writer you can specify the local or remote folder to store results.
28+
I.e. if you want to write results to Google Cloud Storage bucket `gs://PROJECT_ID/bucket`,
29+
you need to provide `destination_folder` parameter.
30+
31+
32+
/// tab | cli
33+
```bash hl_lines="3"
34+
garf query.sql --source API_SOURCE \
35+
--output csv \
36+
--csv.destination-folder=gs://PROJECT_ID/bucket
37+
```
38+
///
39+
40+
/// tab | python
41+
```python
42+
from garf_core import report
43+
from garf_io.writers import csv_writer
44+
45+
# Create example report
46+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
47+
48+
writer = csv_writer.CsvWriter(destination_folder='gs://PROJECT_ID/bucket/')
49+
writer.write(sample_report, 'query')
50+
```
51+
///

docs/usage/json-writer.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
`json` writer allows you to save `GarfReport` as JSON or JSONL file to local or remote storage.
2+
3+
/// tab | cli
4+
```bash
5+
garf query.sql --source API_SOURCE \
6+
--output json
7+
```
8+
///
9+
10+
/// tab | python
11+
```python
12+
from garf_core import report
13+
from garf_io.writers import json_writer
14+
15+
# Create example report
16+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
17+
18+
writer = json_writer.JsonWriter()
19+
writer.write(sample_report, 'query')
20+
```
21+
///
22+
23+
## Parameters
24+
25+
### Destination folder
26+
27+
You can specify the local or remote folder to store results.
28+
I.e. if you want to write results to Google Cloud Storage bucket `gs://PROJECT_ID/bucket`,
29+
you need to provide `destination_folder` parameter.
30+
31+
32+
/// tab | cli
33+
```bash hl_lines="3"
34+
garf query.sql --source API_SOURCE \
35+
--output json \
36+
--json.destination-folder=gs://PROJECT_ID/bucket
37+
```
38+
///
39+
40+
/// tab | python
41+
```python
42+
from garf_core import report
43+
from garf_io.writers import json_writer
44+
45+
# Create example report
46+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
47+
48+
writer = json_writer.JsonWriter(destination_folder='gs://PROJECT_ID/bucket/')
49+
writer.write(sample_report, 'query')
50+
```
51+
///
52+
53+
### Format
54+
55+
You can specify the output format:
56+
57+
* `json` - JSON (default)
58+
* `jsonl` - JSON lines
59+
60+
/// tab | cli
61+
```bash hl_lines="3"
62+
garf query.sql --source API_SOURCE \
63+
--output json \
64+
--json.format=jsonl
65+
```
66+
///
67+
68+
/// tab | python
69+
```python hl_lines="7"
70+
from garf_core import report
71+
from garf_io.writers import json_writer
72+
73+
# Create example report
74+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
75+
76+
writer = json_writer.JsonWriter(format='jsonl')
77+
writer.write(sample_report, 'query')
78+
```
79+
///

docs/usage/sheets-writer.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
!!! important
2+
To save data to Google Sheets install `garf-io` with Google Sheets support
3+
4+
```bash
5+
pip install garf-io[sheets]
6+
```
7+
8+
9+
`sheets` writer allows you to save `GarfReport` to Google Sheets.
10+
11+
/// tab | cli
12+
```bash
13+
garf query.sql --source API_SOURCE \
14+
--output sheets
15+
```
16+
///
17+
18+
/// tab | python
19+
```python
20+
from garf_core import report
21+
from garf_io.writers import sheets_writer
22+
23+
# Create example report
24+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
25+
26+
writer = sheets_writer.SheetsWriter()
27+
writer.write(sample_report, 'query')
28+
```
29+
///

0 commit comments

Comments
 (0)