Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/localstack/verdin
A Tinybird SDK for Python 🐦
https://github.com/localstack/verdin
database-client python sdk tinybird
Last synced: 9 days ago
JSON representation
A Tinybird SDK for Python 🐦
- Host: GitHub
- URL: https://github.com/localstack/verdin
- Owner: localstack
- License: apache-2.0
- Created: 2021-09-25T11:47:20.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-17T13:42:17.000Z (over 2 years ago)
- Last Synced: 2024-04-25T07:02:29.656Z (7 months ago)
- Topics: database-client, python, sdk, tinybird
- Language: Python
- Homepage:
- Size: 36.1 KB
- Stars: 20
- Watchers: 14
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Verdin
======Verdin is a [tiny bird](https://en.wikipedia.org/wiki/Verdin), and also a [Tinybird](https://tinybird.co) SDK for Python
.Install
-------pip install verdin
Requirements
------------Python 3.8+
Usage
-----### Run an SQL Query
```python
# the tinybird module exposes all important tinybird concepts
from verdin import tinybirdclient = tinybird.Client("p.mytoken")
query = client.sql("select * from my_datasource__v0")# run the query with `FORMAT JSON` and receive a QueryJsonResult
response: tinybird.QueryJsonResult = query.json()# print records returned from the pipe
print(response.data)
```You can also run, e.g., `query.get(format=OutputFormat.CSV)` to get the raw response with CSV data.
### Query a Pipe
```python
from verdin import tinybirdclient = tinybird.Client("p.mytoken")
pipe = client.pipe("my_pipe")# query the pipe using dynamic parameters
response: tinybird.PipeJsonResponse = pipe.query({"key": "val"})# print records returned from the pipe
print(response.data)
```### Append to a DataSource
```python
from verdin import tinybirdclient = tinybird.Client("p.mytoken")
# will access my_datasource__v0
datasource = client.datasource("my_datasource", version=0)# query the pipe using dynamic parameters
datasource.append([
("col1-row1", "col2-row1"),
("col1-row2", "col2-row2"),
])
```### Queue and batch records into a DataSource
Verdin provides a way to queue and batch data continuously:
```python
from queue import Queue
from threading import Threadfrom verdin import tinybird
from verdin.worker import QueuingDatasourceAppenderclient = tinybird.Client("p.mytoken")
records = Queue()
appender = QueuingDatasourceAppender(records, client.datasource("my_datasource"))
Thread(target=appender.run).start()# appender will regularly read batches of data from the queue and append them
# to the datasource. the appender respects rate limiting.records.put(("col1-row1", "col2-row1"))
records.put(("col1-row2", "col2-row2"))
```Develop
-------Create the virtual environment, install dependencies, and run tests
make venv
make testRun the code formatter
make format
Upload the pypi package using twine
make upload