Skip to main content

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.

Metadata

Release files for pulsar-selector-filter 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pulsar-selector-filter 1.1.0
File Size Uploaded Provenance Actions
pulsar_selector_filter-1.1.0.tar.gz 25.0 kB With provenance Details for pulsar_selector_filter-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pulsar-selector-filter 1.1.0
File Interpreter ABI Platform Actions
pulsar_selector_filter-1.1.0-py3-none-any.whl Python 3 none any Details for pulsar_selector_filter-1.1.0-py3-none-any.whl

Total release size: 42.4 kB

Release files / pulsar_selector_filter-1.1.0.tar.gz

Download URL pulsar_selector_filter-1.1.0.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2491b079e72f80bed103c345bb4db0cb1e02b04d35b7062d1e431459f1b5b5d5
BLAKE2b-256 checksum
How to use checksums
c995acf4dfbf38c3116fba28d8936113b8c1e60f94bb02cedaa9ad91f49b61a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 28, 2026.

Transparency log

Release files / pulsar_selector_filter-1.1.0-py3-none-any.whl

Download URL pulsar_selector_filter-1.1.0-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
449d7b12e062f6a0dfb80b33d8db8375ba66ab729d0e8c94ea56b091ff51bac5
BLAKE2b-256 checksum
How to use checksums
1d0f4a87bd483348d0723e027e4afb0d07ed26320a14b7dafb53e9e9add6b04c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 28, 2026.

Transparency log

Security for pulsar-selector-filter 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pulsar_selector_filter-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page