|
1 | 1 | # Feldera Python SDK |
2 | 2 |
|
3 | | -Feldera Python is the Feldera SDK for Python developers. |
| 3 | +The `feldera` Python package is the Python client for the Feldera HTTP API. |
4 | 4 |
|
5 | | -## Installation |
| 5 | +The Python SDK documentation is available at: https://docs.feldera.com/python |
| 6 | + |
| 7 | +## Getting started |
| 8 | + |
| 9 | +### Installation |
6 | 10 |
|
7 | 11 | ```bash |
8 | 12 | uv pip install feldera |
9 | 13 | ``` |
10 | 14 |
|
11 | | -### Installing from Github |
| 15 | +### Example usage |
| 16 | + |
| 17 | +The Python client interacts with the API server of the Feldera instance. |
| 18 | + |
| 19 | +```python |
| 20 | +# File: example.py |
| 21 | +from feldera import FelderaClient, PipelineBuilder, Pipeline |
| 22 | + |
| 23 | +# Instantiate client |
| 24 | +client = FelderaClient() # Default: http://localhost:8080 without authentication |
| 25 | +# client = FelderaClient(url="https://localhost:8080", api_key="apikey:...", requests_verify="/path/to/tls.crt") |
| 26 | + |
| 27 | +# (Re)create pipeline |
| 28 | +name = "example" |
| 29 | +sql = """ |
| 30 | +CREATE TABLE t1 (i1 INT) WITH ('materialized' = 'true'); |
| 31 | +CREATE MATERIALIZED VIEW v1 AS SELECT * FROM t1; |
| 32 | +""" |
| 33 | +print("(Re)creating pipeline...") |
| 34 | +pipeline = PipelineBuilder(client, name, sql).create_or_replace() |
| 35 | +pipeline.start() |
| 36 | +print(f"Pipeline status: {pipeline.status()}") |
| 37 | +pipeline.pause() |
| 38 | +print(f"Pipeline status: {pipeline.status()}") |
| 39 | +pipeline.stop(force=True) |
| 40 | + |
| 41 | +# Find existing pipeline |
| 42 | +pipeline = Pipeline.get(name, client) |
| 43 | +pipeline.start() |
| 44 | +print(f"Pipeline status: {pipeline.status()}") |
| 45 | +pipeline.stop(force=True) |
| 46 | +pipeline.clear_storage() |
| 47 | +``` |
12 | 48 |
|
| 49 | +Run using: |
13 | 50 | ```bash |
14 | | -uv pip install git+https://github.com/feldera/feldera#subdirectory=python |
| 51 | +uv run python example.py |
15 | 52 | ``` |
16 | 53 |
|
17 | | -Similarly, to install from a specific branch: |
| 54 | +### Environment variables |
| 55 | + |
| 56 | +Some default parameter values in the Python SDK can be overridden via environment variables. |
| 57 | + |
| 58 | +**Environment variables for `FelderaClient(...)`** |
18 | 59 |
|
19 | 60 | ```bash |
20 | | -uv pip install git+https://github.com/feldera/feldera@{BRANCH_NAME}#subdirectory=python |
| 61 | +export FELDERA_HOST="https://localhost:8080" # Overrides default for `url` |
| 62 | +export FELDERA_API_KEY="apikey:..." # Overrides default for `api_key` |
| 63 | + |
| 64 | +# The following together override default for `requests_verify` |
| 65 | +# export FELDERA_TLS_INSECURE="false" # If set to "1", "true" or "yes" (all case-insensitive), disables TLS certificate verification |
| 66 | +# export FELDERA_HTTPS_TLS_CERT="/path/to/tls.crt" # Custom TLS certificate |
21 | 67 | ``` |
22 | 68 |
|
23 | | -Replace `{BRANCH_NAME}` with the name of the branch you want to install from. |
| 69 | +**Environment variables for `PipelineBuilder(...)`** |
24 | 70 |
|
25 | | -### Installing from Local Directory |
| 71 | +```bash |
| 72 | +export FELDERA_RUNTIME_VERSION="..." # Overrides default for `runtime_version` |
| 73 | +``` |
| 74 | + |
| 75 | +## Development |
26 | 76 |
|
27 | | -If you have cloned the Feldera repo, you can install the python SDK as follows: |
| 77 | +Development assumes you have cloned the Feldera code repository. |
| 78 | + |
| 79 | +### Installation |
28 | 80 |
|
29 | 81 | ```bash |
30 | | -# the Feldera Python SDK is present inside the python/ directory |
31 | 82 | cd python |
32 | | -# If you don't have a virtual environment, create one |
| 83 | +# Optional: create and activate virtual environment if you don't have one |
33 | 84 | uv venv |
34 | | -source .venv/activate |
35 | | -# Install the SDK in editable mode |
36 | | -uv pip install . |
| 85 | +source .venv/bin/activate |
| 86 | +# Install in editable mode |
| 87 | +uv pip install -e . |
37 | 88 | ``` |
38 | 89 |
|
39 | | -## Documentation |
| 90 | +### Formatting |
40 | 91 |
|
41 | | -The Python SDK documentation is available at |
42 | | -[Feldera Python SDK Docs](https://docs.feldera.com/python). |
| 92 | +Formatting requires the `ruff` package: `uv pip install ruff` |
43 | 93 |
|
44 | | -To build the html documentation run: |
| 94 | +```bash |
| 95 | +cd python |
| 96 | +ruff check |
| 97 | +ruff format |
| 98 | +``` |
45 | 99 |
|
46 | | -Ensure that you have sphinx installed. If not, install it using `uv pip install sphinx`. |
| 100 | +### Tests |
47 | 101 |
|
48 | | -Then run the following commands: |
| 102 | +Running the test requires the `pytest` package: `uv pip install pytest` |
49 | 103 |
|
50 | 104 | ```bash |
51 | | -cd docs |
52 | | -sphinx-apidoc -o . ../feldera |
53 | | -make html |
| 105 | +# All tests |
| 106 | +cd python |
| 107 | +uv run python -m pytest tests/ |
| 108 | + |
| 109 | +# Specific tests directory |
| 110 | +uv run python -m pytest tests/platform/ |
| 111 | + |
| 112 | +# Specific test file |
| 113 | +uv run python -m pytest tests/platform/test_pipeline_crud.py |
54 | 114 | ``` |
55 | 115 |
|
56 | | -To clean the build, run `make clean`. |
| 116 | +For further information about the tests, please see `tests/README.md`. |
57 | 117 |
|
58 | | -## Linting and formatting |
| 118 | +### Documentation |
59 | 119 |
|
60 | | -Use [Ruff] to run the lint checks that will be executed by the |
61 | | -precommit hook when a PR is submitted: |
| 120 | +Building documentation requires the `sphinx` package: `uv pip install sphinx` |
62 | 121 |
|
63 | 122 | ```bash |
64 | | -ruff check python/ |
| 123 | +cd python/docs |
| 124 | +sphinx-apidoc -o . ../feldera |
| 125 | +make html |
| 126 | +make clean # Cleanup afterwards |
65 | 127 | ``` |
66 | 128 |
|
67 | | -To reformat the code in the same way as the precommit hook: |
| 129 | +### Installation from GitHub |
68 | 130 |
|
| 131 | +Latest `main` branch: |
69 | 132 | ```bash |
70 | | -ruff format |
| 133 | +uv pip install git+https://github.com/feldera/feldera#subdirectory=python |
71 | 134 | ``` |
72 | 135 |
|
73 | | -[Ruff]: https://github.com/astral-sh/ruff |
| 136 | +Different branch (replace `BRANCH_NAME`): |
| 137 | +```bash |
| 138 | +uv pip install git+https://github.com/feldera/feldera@BRANCH_NAME#subdirectory=python |
| 139 | +``` |
0 commit comments