Skip to content

Commit 6117e74

Browse files
docs: update writers section
1 parent 84ad6c8 commit 6117e74

File tree

1 file changed

+201
-6
lines changed

1 file changed

+201
-6
lines changed

docs/usage/writers.md

Lines changed: 201 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ Each of writer also support two options for dealing with arrays:
2020

2121
## Installation
2222

23-
`pip install garf-io`
23+
/// tab | pip
24+
```bash
25+
pip install garf-io
26+
```
27+
///
28+
29+
/// tab | uv
30+
```bash
31+
uv add garf-io
32+
```
33+
///
2434

2535
By default `garf-io` has only support for `console`, `csv` and `json` writers.
2636

@@ -35,16 +45,201 @@ To install specific writers use:
3545

3646
## Usage
3747

48+
!!!note
49+
To use `cli` example you need to have `garf-executors` package installed.
50+
51+
```bash
52+
pip install garf-executors
53+
```
54+
55+
/// tab | cli
56+
```bash
57+
garf query.sql --source API_SOURCE \
58+
--output YOUR_WRITER
59+
```
60+
///
61+
62+
/// tab | python
3863
```python
39-
import garf_core import report
64+
from garf_core import report
4065
from garf_io import writer
4166

4267
# Create example report
4368
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
4469

45-
# Initialize CSV writer
46-
concrete_writer = writer.create_writer('csv', destination_folder='/tmp/')
70+
concrete_writer = writer.create_writer('YOUR_WRITER')
71+
concrete_writer.write(sample_report, 'query')
72+
```
73+
///
74+
75+
76+
### Console
77+
78+
`console` writer allows you to print `GarfReport` to standard output in the terminal.
79+
80+
/// tab | cli
81+
```bash
82+
garf query.sql --source API_SOURCE \
83+
--output console
84+
```
85+
///
86+
87+
/// tab | python
88+
```python
89+
from garf_core import report
90+
from garf_io.writers import console_writer
91+
92+
# Create example report
93+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
94+
95+
writer = console_writer.ConsoleWriter()
96+
writer.write(sample_report, 'query')
97+
```
98+
///
99+
100+
101+
### CSV
102+
103+
`csv` writer allows you to save `GarfReport` as a CSV file to local or remote storage.
104+
105+
/// tab | cli
106+
```bash
107+
garf query.sql --source API_SOURCE \
108+
--output csv
109+
```
110+
///
111+
112+
/// tab | python
113+
```python
114+
from garf_core import report
115+
from garf_io.writers import csv_writer
116+
117+
# Create example report
118+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
119+
120+
writer = csv_writer.CsvWriter()
121+
writer.write(sample_report, 'query')
122+
```
123+
///
124+
125+
### JSON
126+
127+
`json` writer allows you to save `GarfReport` as JSON or JSONL file to local or remote storage.
128+
129+
/// tab | cli
130+
```bash
131+
garf query.sql --source API_SOURCE \
132+
--output json
133+
```
134+
///
135+
136+
/// tab | python
137+
```python
138+
from garf_core import report
139+
from garf_io.writers import json_writer
140+
141+
# Create example report
142+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
143+
144+
writer = json_writer.JsonWriter()
145+
writer.write(sample_report, 'query')
146+
```
147+
///
148+
149+
### BigQuery
150+
151+
!!! important
152+
To save data to BigQuery install `garf-io` with BigQuery support
153+
154+
```bash
155+
pip install garf-io[bq]
156+
```
157+
158+
159+
`bq` writer allows you to save `GarfReport` to BigQuery table.
160+
161+
/// tab | cli
162+
```bash
163+
garf query.sql --source API_SOURCE \
164+
--output bq
165+
```
166+
///
167+
168+
/// tab | python
169+
```python
170+
from garf_core import report
171+
from garf_io.writers import bigquery_writer
172+
173+
# Create example report
174+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
175+
176+
writer = bigquery_writer.BigQueryWriter()
177+
writer.write(sample_report, 'query')
178+
```
179+
///
180+
181+
### Google Sheets
182+
183+
!!! important
184+
To save data to Google Sheets install `garf-io` with Google Sheets support
185+
186+
```bash
187+
pip install garf-io[sheets]
188+
```
189+
190+
191+
`sheets` writer allows you to save `GarfReport` to Google Sheets.
192+
193+
/// tab | cli
194+
```bash
195+
garf query.sql --source API_SOURCE \
196+
--output sheets
197+
```
198+
///
199+
200+
/// tab | python
201+
```python
202+
from garf_core import report
203+
from garf_io.writers import sheets_writer
204+
205+
# Create example report
206+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
207+
208+
writer = sheets_writer.SheetsWriter()
209+
writer.write(sample_report, 'query')
210+
```
211+
///
212+
213+
### SqlAlchemy
214+
215+
!!! important
216+
To save data to Google Sheets install `garf-io` with SqlAlchemy support
217+
218+
```bash
219+
pip install garf-io[sqlalchemy]
220+
```
221+
222+
223+
`sqldb` writer allows you to save `GarfReport` to SqlAlchemy supported table databases.
224+
225+
/// tab | cli
226+
```bash
227+
garf query.sql --source API_SOURCE \
228+
--output sqldb
229+
```
230+
///
231+
232+
/// tab | python
233+
```python
234+
from garf_core import report
235+
from garf_io.writers import sqldb_writer
236+
237+
# Create example report
238+
sample_report = report.GarfReport(results=[[1]], column_names=['one'])
47239

48-
# Write data to /tmp/sample.csv
49-
concrete_writer.write(sample_report, 'sample')
240+
writer = sqldb_writer.SqlAlchemyWriter(
241+
connection_string=SQLALCHEMY_CONNECTION_STRING
242+
)
243+
writer.write(sample_report, 'query')
50244
```
245+
///

0 commit comments

Comments
 (0)