Skip to main content

Redis IO plugin for Polars

Project description

polars-redis

Query Redis like a database. Transform with Polars. Write back without ETL.

New to Polars? Polars is a lightning-fast DataFrame library for Python and Rust. Check out the Polars User Guide to get started.

CI PyPI Crates.io Downloads Python Docs License

What is polars-redis?

polars-redis makes Redis a first-class data source in your Polars workflows. Query, transform, and write back - Redis becomes just another connector alongside Parquet, CSV, and databases.

import polars as pl
import polars_redis as redis

# Redis is just another source
users = redis.read_hashes(url, "user:*", schema)
orders = pl.read_parquet("s3://bucket/orders.parquet")

# Full Polars transformation power
result = (
    users.join(orders, on="user_id")
    .group_by("region")
    .agg(pl.col("amount").sum())
)

# Write back to Redis
redis.write_hashes(result, url, key_prefix="region_stats:")

Installation

pip install polars-redis

When to Use What

Your data Use Why
User profiles, configs scan_hashes() Field-level access, projection pushdown
Nested documents scan_json() Full document structure
Counters, flags, caches scan_strings() Simple key-value
Tags, memberships scan_sets() Unique members
Queues, recent items scan_lists() Ordered elements
Leaderboards, rankings scan_zsets() Score-based ordering

Quick Start

import polars as pl
import polars_redis as redis

url = "redis://localhost:6379"

# Scan with schema
lf = redis.scan_hashes(
    url,
    pattern="user:*",
    schema={"name": pl.Utf8, "age": pl.Int64, "active": pl.Boolean},
)

# Filter and collect (projection pushdown applies)
active_users = lf.filter(pl.col("active")).select(["name", "age"]).collect()

# Write with TTL
redis.write_hashes(active_users, url, key_prefix="cache:user:", ttl=3600)

RediSearch (Server-Side Filtering)

from polars_redis import col

# Filter in Redis, not Python - only matching docs are transferred
df = redis.search_hashes(
    url,
    index="users_idx",
    query=(col("age") > 30) & (col("status") == "active"),
    schema={"name": pl.Utf8, "age": pl.Int64, "status": pl.Utf8},
).collect()

# Server-side aggregation
df = redis.aggregate_hashes(
    url,
    index="users_idx",
    query="*",
    group_by=["@department"],
    reduce=[("COUNT", [], "count"), ("AVG", ["@salary"], "avg_salary")],
)

Parallel Fetching

# Speed up large scans with parallel workers
lf = redis.scan_hashes(
    url,
    pattern="user:*",
    schema={"name": pl.Utf8, "age": pl.Int64},
    parallel=4,  # Use 4 parallel workers
)

Features

Read:

  • scan_hashes() / read_hashes() - Redis hashes
  • scan_json() / read_json() - RedisJSON documents
  • scan_strings() / read_strings() - Redis strings
  • scan_sets() / read_sets() - Redis sets
  • scan_lists() / read_lists() - Redis lists
  • scan_zsets() / read_zsets() - Redis sorted sets
  • Projection pushdown (fetch only requested fields)
  • Schema inference (infer_hash_schema(), infer_json_schema())
  • Metadata columns (key, TTL, row index)
  • Parallel fetching for improved throughput

RediSearch (Predicate Pushdown):

  • search_hashes() - Server-side filtering with FT.SEARCH
  • aggregate_hashes() - Server-side aggregation with FT.AGGREGATE
  • Polars-like query builder: col("age") > 30

Write:

  • write_hashes(), write_json(), write_strings()
  • write_sets(), write_lists(), write_zsets()
  • TTL support
  • Key prefix
  • Write modes: fail, replace, append

Supported Types

Polars Redis
Utf8 string
Int64 parsed int
Float64 parsed float
Boolean true/false, 1/0, yes/no
Date YYYY-MM-DD or epoch days
Datetime ISO 8601 or Unix timestamp

Requirements

  • Python 3.9+
  • Redis 7.0+ (RedisJSON module for JSON support)

Documentation

Full documentation at joshrotenberg.github.io/polars-redis

License

MIT or Apache-2.0

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

polars_redis-0.1.6.tar.gz (305.5 kB view details)

Uploaded Source

Built Distributions

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

polars_redis-0.1.6-cp314-cp314-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

polars_redis-0.1.6-cp314-cp314-macosx_10_12_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

polars_redis-0.1.6-cp39-cp39-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.9Windows x86-64

polars_redis-0.1.6-cp38-cp38-manylinux_2_24_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.24+ x86-64

File details

Details for the file polars_redis-0.1.6.tar.gz.

File metadata

  • Download URL: polars_redis-0.1.6.tar.gz
  • Upload date:
  • Size: 305.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polars_redis-0.1.6.tar.gz
Algorithm Hash digest
SHA256 67a4754142bd77093d4c43b459a0d257449a251661d3e86abb722f370c5f7002
MD5 e16c497f9083351a17f825d633592b32
BLAKE2b-256 9554d1f6aee7a893fb511c7e5eb59e9b6ae99e2b0b047cd2ae478ab37dc4e7a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_redis-0.1.6.tar.gz:

Publisher: publish.yml on joshrotenberg/polars-redis

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

File details

Details for the file polars_redis-0.1.6-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_redis-0.1.6-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0790567eba8f916051c8efb0a157c9452628561be2f0e250260452469a05c92a
MD5 eb7f464608f365aea1168c5ca8eb5391
BLAKE2b-256 d29cd26741aa2db7d19c85ca176fb0b552d395201c0911b2221393685ee9fb0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_redis-0.1.6-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: publish.yml on joshrotenberg/polars-redis

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

File details

Details for the file polars_redis-0.1.6-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_redis-0.1.6-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dadd8e312500dd5bb6f1504a124d58f2f1ad8cf7b993fe2511ab31af94865b2f
MD5 f5160f8299d660f5d24cc1f28930a99e
BLAKE2b-256 9228cf2463a8a5f5fe04d742695357dc7cda57e0b07548d4321cfbfd4393bf75

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_redis-0.1.6-cp314-cp314-macosx_10_12_x86_64.whl:

Publisher: publish.yml on joshrotenberg/polars-redis

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

File details

Details for the file polars_redis-0.1.6-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: polars_redis-0.1.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polars_redis-0.1.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 26d8e56fb80330548d605355e9d1e8565fc9f690e71be857f86e4e449c63f654
MD5 bba1b821146600deb97bde5f2ed2231b
BLAKE2b-256 d09bfe5614210c13560e57fef742bceb0bb3d1de3dd15f6ff407d5236a8b9e7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_redis-0.1.6-cp39-cp39-win_amd64.whl:

Publisher: publish.yml on joshrotenberg/polars-redis

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

File details

Details for the file polars_redis-0.1.6-cp38-cp38-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for polars_redis-0.1.6-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 5aec490480d94f75ec651b7896e2a7ac2fc0e3b7fa9517d35b347879ae0b91be
MD5 38dc4d4a6e1d050e0aec1a38abf05f56
BLAKE2b-256 9ea1eda4b07cc8234d233856db63f313912c67af1b86fb032f4acf70b413c2f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_redis-0.1.6-cp38-cp38-manylinux_2_24_x86_64.whl:

Publisher: publish.yml on joshrotenberg/polars-redis

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