Skip to main content

Broker-side selector filter SDK for Apache Pulsar — orchestrator-fronted filtered consumers via JMS-selector expressions.

Project description

pulsar-selector-filter — Python SDK

Python client for the broker-side selector filter system on Apache Pulsar. Mirrors the public API of the Java SDK at sdk/java/pulsar/ and speaks the same JSON wire format. See the top-level README for the architecture overview.

Status: alpha (0.1.x). The full SDK surface is implemented and tested end-to-end against the Java orchestrator. The API is stable in shape but field-level details may shift before 1.0. Track progress in tasks/todo-python-sdk.md.

Install

From source (today)

pip install "git+https://github.com/david-streamlio/broker-side-filtering-function.git@main#subdirectory=sdk/python"

From a GitHub release wheel (once published)

pip install https://github.com/.../releases/download/vX.Y.Z/pulsar_selector_filter-X.Y.Z-py3-none-any.whl

From PyPI (once published)

pip install pulsar-selector-filter

Supported Python versions

3.9+. The Pulsar Python client itself supports 3.8+, but the broader ecosystem (mypy, pandas, numpy) has dropped 3.8. Tested in CI on 3.9, 3.10, 3.11, 3.12, 3.13.

Quickstart

import pulsar
from selector_filter import Session

client = pulsar.Client("pulsar://broker:6650")

with Session.builder() \
        .pulsar_client(client) \
        .control_topic("persistent://public/filters/filter-requests") \
        .build() as session:

    with session.new_consumer() \
            .topic("persistent://public/in/trades") \
            .selector("region = 'US'") \
            .subscribe() as consumer:

        msg = consumer.receive(timeout_millis=5000)
        print(msg.data(), msg.properties())
        consumer.acknowledge(msg)

        # Hot-reload the selector at runtime — same queryId.
        consumer.set_selector("region IN ('US','UK')")

client.close()

The Session publishes one HEARTBEAT message every 30 seconds covering every live queryId it owns; the orchestrator uses these to detect SDK consumers that died without calling close(). Opt out via .disable_heartbeat() if you have a controlled shutdown story or do not want the chatter.

Public surface

Class / fn Purpose
Session / SessionBuilder Entry point; owns the producer on the orchestrator control topic and the daemon heartbeat scheduler
FilteringConsumer Wraps a Pulsar consumer on the SDK-generated private output topic. Methods: receive, acknowledge, negative_acknowledge, iteration; control: query_id, current_selector, set_selector
ConsumerBuilder Fluent builder returned by Session.new_consumer()
PrivateQuery Handle returned by Session.register_private_query
PrivateTopicPolicy Per-query private-output-topic settings (currently informational; see Limits)
FilterRequest / Command / ClientType Wire-format types (mostly internal; exported for advanced users)

Limits

  • Per-topic policies are not applied to private topics. The Pulsar Python client does not ship a PulsarAdmin equivalent, so the SDK does not set per-topic TTL / retention / inactive-delete policies. Operators must configure equivalent defaults at the namespace level. A follow-up may add a thin HTTP wrapper for the relevant REST endpoints.
  • Client-side JMS-selector syntax validation is a no-op. The Java SDK uses the pulsar-jms-filters library to fail malformed selectors at register time. Python has no equivalent parser today; malformed selectors are rejected asynchronously by the orchestrator, so a bad selector means a quiet REGISTER followed by no records arriving on the private topic.
  • Sync-only. The SDK is synchronous. An asyncio variant can be added in a later phase without changing the sync surface.

Development

cd sdk/python
python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"

# Lint + type-check
.venv/bin/ruff check src/ tests/
.venv/bin/mypy src/

# Run unit tests
.venv/bin/pytest tests/ --ignore=tests/integration

# Run the live IT (requires Docker + pre-built NARs)
.venv/bin/pip install -e ".[it]"
mvn -pl functions/selector-filter,functions/orchestrator package -DskipTests \
    -f ../../pom.xml
.venv/bin/pytest tests/integration/ -v

# Build wheel + sdist
.venv/bin/hatch build

Cross-language wire parity

The Python SDK speaks the exact same JSON wire format as the Java SDK. Unit tests include a cross-language parity suite (tests/test_filter_request_serde.py::TestJavaWireParity) that round-trips the canonical examples from protocol/filter-request.schema.json through the Python implementation and asserts the on-wire shape matches what the Java side emits. The live IT (tests/integration/test_orchestrator_e2e.py) proves end-to-end interop: Python consumer → Java orchestrator → Java filter function → Python consumer receives filtered output.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pulsar_selector_filter-1.1.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pulsar_selector_filter-1.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file pulsar_selector_filter-1.1.0.tar.gz.

File metadata

  • Download URL: pulsar_selector_filter-1.1.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pulsar_selector_filter-1.1.0.tar.gz
Algorithm Hash digest
SHA256 2491b079e72f80bed103c345bb4db0cb1e02b04d35b7062d1e431459f1b5b5d5
MD5 4e65f08d60ed40f702e4ee8ab74f2f71
BLAKE2b-256 c995acf4dfbf38c3116fba28d8936113b8c1e60f94bb02cedaa9ad91f49b61a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulsar_selector_filter-1.1.0.tar.gz:

Publisher: release-python.yml on david-streamlio/broker-side-filtering-function

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pulsar_selector_filter-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pulsar_selector_filter-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 449d7b12e062f6a0dfb80b33d8db8375ba66ab729d0e8c94ea56b091ff51bac5
MD5 a0e5597a0888cf0737ef3ab248a21f15
BLAKE2b-256 1d0f4a87bd483348d0723e027e4afb0d07ed26320a14b7dafb53e9e9add6b04c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulsar_selector_filter-1.1.0-py3-none-any.whl:

Publisher: release-python.yml on david-streamlio/broker-side-filtering-function

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page