Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
**/node_modules/**
ts/**/dist
tsconfig.tsbuildinfo
uv.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ An experiment in ETL architecture for data services on The Graph. 'Project Nozzl

### Python Quickstart

To quickly dive into the power of Nozzle with Python, best is to run the [`getting-started.ipynb](python/examples/getting-started.ipynb). Follow the instructions in thy [Python README](python/README.md).
To quickly dive into the power of Nozzle with Python, best is to run the [`marimo_example_nb.ipynb](python/notebooks/marimo_example_nb.pyy). Follow the instructions in thy [Python README](python/README.md).

## Components

Expand Down
77 changes: 65 additions & 12 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
# Getting started with the Python client
# Python Nozzle Client

To get started with the Python client, you will need
[`poetry`](https://python-poetry.org/)
installed locally. With that, run `poetry install` in this directory. That
will install all required dependencies, including
[Jupyter](https://jupyter.org/)
Client for issuing queries to a nozzle server and working with the returned data.

## Installation

1. Ensure you have [`uv`](https://docs.astral.sh/uv/getting-started/installation/) installed locally.
2. Install dependencies
```bash
uv build
```
3. Activate a virtual environment
```bash
uv venv
```

You will need to have the files that [`dump`](../dump) produces available
locally, and run the [server](../server) You can then start Jupyter with
```shell
poetry run jupyter notebook examples/
## Useage

### Marimo

Start up a marimo workspace editor
```bash
uv run marimo edit
```

The Marimo app will open a new browser tab where you can create a new notebook, view helpful resources, and
browse existing notebooks in the workspace.

### Apps

You can execute python apps and scripts using `uv run <path>` which will give them access to the dependencies
and the `nozzle` package. For example, you can run the `execute_query` app with the following command.
```bash
uv run apps/execute_query.py
```

That will open a new browser tab. In that, double click on
`getting-started.ipynb` and select `Run > Run All Cells` from the menu.
# Self-hosted nozzle server

In order to operate a local nozzle server you will need to have the files
that [`dump`](../dump) produces available locally, and run the [server](../server)
You can then use it in your python scripts, apps or notebooks.

# Testing

The project is set up to use the [`pytest`](https://docs.pytest.org/en/stable/) testing framework.
It follows [standard python test discovery rules](https://docs.pytest.org/en/stable/explanation/goodpractices.html#test-discovery).

Run all tests
```bash
uv run pytest
```

# Linting and formatting

Ruff is configured to be used for linting and formatting of this project.

Run formatter
```bash
uv run ruff format
```

Run linter
```bash
uv run ruff check .
```

Run linter and apply auto-fixes
```bash
uv run ruff check . --fix
```
File renamed without changes.
8 changes: 8 additions & 0 deletions python/apps/execute_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rich import print

from nozzle.client import Client

client = Client('grpc://34.27.238.174:80')

df = client.get_sql('select * from eth_firehose.logs limit 1', read_all=True).to_pandas()
print(df)
27 changes: 27 additions & 0 deletions python/apps/query_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import List, Optional

import typer
from rich import print

from nozzle.client import Client

app = typer.Typer()


@app.command()
def query(table: str, columns: Optional[List[str]] = None, where: Optional[List[str]] = None, limit: Optional[int] = 1):
client = Client('grpc://34.27.238.174:80')
print('send ze query :rocket:')
columns_query = '*' if not columns else columns
where_query = '' if not where else f'where {where}'
limit_query = 'limit 1' if not limit else f'limit {limit}'
query_body = f'select {columns_query} from {table} {where_query} {limit_query}'
print(f'... {query_body}\n')

df = client.get_sql(query_body, read_all=True).to_pandas()
print('results:')
print(df)


if __name__ == '__main__':
app()
68 changes: 0 additions & 68 deletions python/examples/getting-started.ipynb

This file was deleted.

Loading