fsspec-kafka
Kafka topics and partitions through fsspec
Overview
fsspec-kafka registers Kafka with fsspec. Topics are directories, and messages read as Arrow, Parquet, CSV, or JSON Lines. Each protocol arranges a topic's messages in one way:
| Protocol | Layout | Contents |
|---|---|---|
kafka+offset://, kafka:// |
topic/{partition}/{start}-{end}.arrow |
Fixed offset windows of each partition |
kafka+time:// |
topic/{YYYY}/{MM}/{DD}/{hh}/{mm}/{ss}/{mmm}.arrow |
Messages by UTC timestamp, plus topic/weeks/ |
kafka+records:// |
topic/{key...} |
The latest value of each key in a compacted topic |
kafka+history:// |
topic/{key...} |
Every message of each key |
In every protocol, topic.parquet (or another extension) reads the whole topic; in kafka+records, it holds the latest message of each key.
import fsspec
import pandas as pd
options = {"bootstrap.servers": "localhost:9092"}
fs = fsspec.filesystem("kafka", **options)
fs.ls("orders/0", detail=False) # ["orders/0/0-10000.arrow", ..., "orders/0/20000-.arrow"]
frame = pd.read_parquet("kafka://orders.parquet", storage_options=options)
Storage options are librdkafka properties, except for these:
| Option | Default | Meaning |
|---|---|---|
timeout |
10.0 |
Seconds to wait for broker requests |
window_size |
10000 |
Offsets per kafka+offset window |
time_bucket |
"millisecond" |
Deepest kafka+time level: year through millisecond |
list_format |
"arrow" |
Extension used when listing message files |
batch_size |
1024 |
Messages per Arrow record batch |
allow_admin |
False |
Lets mkdir create topics and rmdir delete them |
partitions, replication |
-1 |
Settings for created topics; -1 uses the broker default |
topic_config |
{} |
Configuration for created topics |
value_format |
"binary" |
"json", "avro", or "confluent" decodes values with value_schema |
value_schema |
None |
pyarrow.Schema or fsspec-data schema reference |
flatten_value |
False |
Puts JSON fields beside the message columns |
key_column |
None |
Input column for message keys when appending |
partition_column |
None |
Input column for partitions when appending |
timestamp_column |
None |
Input column for timestamps when appending |
headers_column |
None |
Input column for headers, a map, when appending |
Messages are read with topic, partition, offset, timestamp, key, headers, and value columns. With value_format="json", value is a struct of the value_schema fields, which are null for tombstones. flatten_value=True puts the fields beside the other columns instead, which CSV needs because it cannot hold structs:
schema = pa.schema([("id", pa.int64()), ("status", pa.string())])
frame = pd.read_csv("kafka://orders.csv", storage_options={**options, "value_format": "json", "value_schema": schema, "flatten_value": True})
value_schema can also be anything fsspec-data resolves when it is installed, such as a list of {"name": ..., "type": ...} fields or a SchemaRef to a schema file or Confluent Schema Registry subject. value_format="avro" reads bare Avro records with an .avsc reference or an Avro schema dict. value_format="confluent" reads and writes values in Confluent wire format, with JSON Schema or Avro subjects. For Avro subjects, every registered version is fetched so older messages resolve to the referenced version's schema. Appends write the schema ID of the Confluent reference:
from fsspec_data import SchemaRef
schema = SchemaRef("confluent://orders-value/versions/latest", storage_options={"registry_url": "http://localhost:8081"})
fs = fsspec.filesystem("kafka", **options, value_format="confluent", value_schema=schema, flatten_value=True)
Topics are append-only. Opening topic.format, or topic/partition.format in kafka+offset, with mode "ab" produces one message per row of the file when it closes. The mapped columns set the message fields, and the remaining columns are the value: a JSON object with value_format="json", an Avro record with Avro values, otherwise a single binary or string column. CSV and JSON Lines columns are typed from value_schema.
fs = fsspec.filesystem("kafka", **options, value_format="json", value_schema=schema, key_column="order_id")
with fs.open("orders.parquet", "ab") as file:
frame.to_parquet(file)
Options can also come from fsspec configuration, for example FSSPEC_KAFKA='{"bootstrap.servers": "localhost:9092"}'.
fs.metadata("orders") returns a topic's configuration and, for each partition, its leader, replicas, in-sync replicas, and low and high watermarks. fs.metadata("orders/0") returns one partition's. fs.offsets_for_time("orders", time) returns the first offset at or after a time in each partition.
kafka+time nests UTC time buckets from years down to time_bucket, which defaults to milliseconds. Each bucket is a directory of the next level, and with an extension, such as orders/2026/11.parquet, a file of its messages. Buckets at the time_bucket level and the ISO weeks in topic/weeks/ are listed as files. Listings cover the time between a topic's first and last messages. Reads use the broker's time index, which assumes timestamps increase with offsets within a partition.
fs = fsspec.filesystem("kafka+time", **options, time_bucket="hour")
fs.ls("orders/2026/11/17", detail=False) # ["orders/2026/11/17/00.arrow", ...]
frame = pd.read_parquet("kafka+time://orders/weeks/2026-W47.parquet", storage_options=options)
kafka+records keeps the latest value of each key in a compacted topic, so it works as a key-value store. Writing a key produces a message and deleting it produces a tombstone. With allow_admin=True, mkdir("state") creates a compacted topic without time retention.
state = fsspec.get_mapper("kafka+records://state", **options)
state["user/42"] = b"..."
kafka+history lists the same keys in any topic, and each key reads as a list_format file of every retained message with that key, including tombstones. Listing keys and reading a key both read the whole topic.
Every Kafka filesystem is an fsspec-data data source, so a dataview renders its topics, partitions, time buckets, and keys as Parquet, CSV, or JSON files, and each topic's and partition's metadata as .metadata.json:
frame = pd.read_parquet("dataview://orders/2026.parquet::kafka+time://", storage_options={"kafka+time": options})
fs.stream follows a topic or one partition as it grows, returning pyarrow.RecordBatch objects with the same columns as .arrow files. It starts at "end" by default; "beginning", a datetime, or the positions of an earlier stream are also accepted.
with fs.stream("orders", start="beginning") as stream:
for batch in stream: # waits for new messages
handle(batch)
save(stream.positions) # {partition: next offset}, to resume with start=positions
From Rust, register the Kafka protocols with an fsspec-rs FilesystemRegistry and open URLs with the same storage options. value_format accepts only binary here, and topic_config.<name> keys set the configuration of created topics; construct KafkaFs with KafkaFsOptions for decoded values.
let mut registry = fsspec_rs::FilesystemRegistry::default();
fsspec_kafka::register(&mut registry);
let options = [("bootstrap.servers".to_string(), "localhost:9092".to_string())].into();
let (fs, path) = registry.url_to_fs("kafka://orders/0", &options)?;
Metadata
Release files for fsspec-kafka 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fsspec_kafka-0.3.1.tar.gz | 142.1 kB | Without provenance | Details for fsspec_kafka-0.3.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| fsspec_kafka-0.3.1-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for fsspec_kafka-0.3.1-cp311-abi3-win_amd64.whl |
| fsspec_kafka-0.3.1-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details for fsspec_kafka-0.3.1-cp311-abi3-manylinux_2_28_x86_64.whl |
| fsspec_kafka-0.3.1-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details for fsspec_kafka-0.3.1-cp311-abi3-manylinux_2_28_aarch64.whl |
| fsspec_kafka-0.3.1-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for fsspec_kafka-0.3.1-cp311-abi3-macosx_11_0_arm64.whl |
Total release size: 49.5 MB
Release files / fsspec_kafka-0.3.1.tar.gz
| Download URL | fsspec_kafka-0.3.1.tar.gz |
|---|---|
| Size | 142.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
073a0adaa549aad44d2744ce04dd7f00d46997a68efd32468fe231268c19aa55
|
|
BLAKE2b-256 checksum How to use checksums |
c9c809a9db44dd9b3bbcd58486cc92fbc953a0abd83a1440247a22fb081a958f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / fsspec_kafka-0.3.1-cp311-abi3-win_amd64.whl
| Download URL | fsspec_kafka-0.3.1-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 11.1 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
59c47ed33882ae96080e7231053166f98bb182d5d4faaf3270c285015cb4611c
|
|
BLAKE2b-256 checksum How to use checksums |
1dcdb137aa9b1c4c364d08e04e605c9508121d8f23d6ebdbe50628358252cabd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / fsspec_kafka-0.3.1-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | fsspec_kafka-0.3.1-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 13.6 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
40552733e47cae06cf9846ee265b43bcdeb910a692377344fe67d33647990851
|
|
BLAKE2b-256 checksum How to use checksums |
be21fa76dbb46b7694ba59fa78c332f398cf0d097ca699a918d175b492eb390e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / fsspec_kafka-0.3.1-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | fsspec_kafka-0.3.1-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 13.4 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
8ebbadb3c1ed688b23067b35899e537dee0a61495051ed1a526ea811d2826f45
|
|
BLAKE2b-256 checksum How to use checksums |
957fe5c01280e38474b4e9653a3e85b16364621594e07217e0623e095b1fba49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / fsspec_kafka-0.3.1-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | fsspec_kafka-0.3.1-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 11.2 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
925cbc4fca5bb1b4adfc96d765c978a597bbd9dc101f134edca0c1fbaedd2cb0
|
|
BLAKE2b-256 checksum How to use checksums |
61eec3740880275abb379b3c2318ad316eea6be6a80127a5eed338a5d5b990e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Security for fsspec-kafka 0.3.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.