Skip to content

Commit a309e51

Browse files
committed
python: refactor README and remove Kafka dev dependency
README changes: - Example usage - Explain environment variables - General restructuring Removes the `kafka-python-ng` Python dev dependency along with the Kafka-related test environment variables as they are not used anywhere currently. Signed-off-by: Simon Kassing <simon.kassing@feldera.com>
1 parent d3c6ce8 commit a309e51

File tree

5 files changed

+97
-51
lines changed

5 files changed

+97
-51
lines changed

python/README.md

Lines changed: 97 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,139 @@
11
# Feldera Python SDK
22

3-
Feldera Python is the Feldera SDK for Python developers.
3+
The `feldera` Python package is the Python client for the Feldera HTTP API.
44

5-
## Installation
5+
The Python SDK documentation is available at: https://docs.feldera.com/python
6+
7+
## Getting started
8+
9+
### Installation
610

711
```bash
812
uv pip install feldera
913
```
1014

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+
```
1248

49+
Run using:
1350
```bash
14-
uv pip install git+https://github.com/feldera/feldera#subdirectory=python
51+
uv run python example.py
1552
```
1653

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(...)`**
1859

1960
```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
2167
```
2268

23-
Replace `{BRANCH_NAME}` with the name of the branch you want to install from.
69+
**Environment variables for `PipelineBuilder(...)`**
2470

25-
### Installing from Local Directory
71+
```bash
72+
export FELDERA_RUNTIME_VERSION="..." # Overrides default for `runtime_version`
73+
```
74+
75+
## Development
2676

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
2880

2981
```bash
30-
# the Feldera Python SDK is present inside the python/ directory
3182
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
3384
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 .
3788
```
3889

39-
## Documentation
90+
### Formatting
4091

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`
4393

44-
To build the html documentation run:
94+
```bash
95+
cd python
96+
ruff check
97+
ruff format
98+
```
4599

46-
Ensure that you have sphinx installed. If not, install it using `uv pip install sphinx`.
100+
### Tests
47101

48-
Then run the following commands:
102+
Running the test requires the `pytest` package: `uv pip install pytest`
49103

50104
```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
54114
```
55115

56-
To clean the build, run `make clean`.
116+
For further information about the tests, please see `tests/README.md`.
57117

58-
## Linting and formatting
118+
### Documentation
59119

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`
62121

63122
```bash
64-
ruff check python/
123+
cd python/docs
124+
sphinx-apidoc -o . ../feldera
125+
make html
126+
make clean # Cleanup afterwards
65127
```
66128

67-
To reformat the code in the same way as the precommit hook:
129+
### Installation from GitHub
68130

131+
Latest `main` branch:
69132
```bash
70-
ruff format
133+
uv pip install git+https://github.com/feldera/feldera#subdirectory=python
71134
```
72135

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+
```

python/feldera/testutils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ def _get_effective_api_key():
4343
or os.environ.get("FELDERA_BASE_URL")
4444
or "http://localhost:8080"
4545
)
46-
KAFKA_SERVER = os.environ.get("FELDERA_KAFKA_SERVER", "localhost:19092")
47-
PIPELINE_TO_KAFKA_SERVER = os.environ.get(
48-
"FELDERA_PIPELINE_TO_KAFKA_SERVER", "redpanda:9092"
49-
)
5046
FELDERA_REQUESTS_VERIFY = requests_verify_from_env()
5147

5248

python/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Issues = "https://github.com/feldera/feldera/issues"
3838

3939
[tool.uv]
4040
dev-dependencies = [
41-
"kafka-python-ng==2.2.2",
4241
"pytest-timeout>=2.3.1",
4342
"pytest-xdist>=3.8.0",
4443
"pytest>=8.3.5",

python/tests/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
enterprise_only,
55
API_KEY,
66
BASE_URL,
7-
PIPELINE_TO_KAFKA_SERVER,
8-
KAFKA_SERVER,
97
FELDERA_REQUESTS_VERIFY,
108
)
119

@@ -15,7 +13,5 @@
1513
"enterprise_only",
1614
"API_KEY",
1715
"BASE_URL",
18-
"PIPELINE_TO_KAFKA_SERVER",
19-
"KAFKA_SERVER",
2016
"FELDERA_REQUESTS_VERIFY",
2117
]

python/uv.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)