Skip to main content

Superstream optimisation library for Kafka producers

Project description

Superclient Python

A Python library for automatically optimizing Kafka producer configurations based on topic-specific recommendations.

Overview

Superstream Clients works as a Python import hook that intercepts Kafka producer creation and applies optimized configurations without requiring any code changes in your application. It dynamically retrieves optimization recommendations from Superstream and applies them based on impact analysis.

Supported Libraries

Works with any Python library that implements Kafka producers, including:

  • kafka-python
  • aiokafka
  • confluent-kafka
  • Faust
  • FastAPI event publishers
  • Celery Kafka backends
  • Any custom wrapper around these Kafka clients

Features

  • Zero-code integration: No code changes required in your application
  • Dynamic configuration: Applies optimized settings based on topic-specific recommendations
  • Intelligent optimization: Identifies the most impactful topics to optimize
  • Graceful fallback: Falls back to default settings if optimization fails
  • Minimal overhead: Uses a single lightweight background thread (or async coroutine for aiokafka)

Important: Producer Configuration Requirements

When initializing your Kafka producers, please ensure you pass the configuration as a mutable object. The Superstream library needs to modify the producer configuration to apply optimizations. The following initialization patterns are supported:

Supported (Recommended):

# Using kafka-python
from kafka import KafkaProducer
producer = KafkaProducer(
    bootstrap_servers=['localhost:9092'],
    compression_type='snappy',
    batch_size=16384
)

# Using aiokafka
from aiokafka import AIOKafkaProducer
producer = AIOKafkaProducer(
    bootstrap_servers='localhost:9092',
    compression_type='snappy',
    batch_size=16384
)

# Using confluent-kafka
from confluent_kafka import Producer
producer = Producer({
    'bootstrap.servers': 'localhost:9092',
    'compression.type': 'snappy',
    'batch.size': 16384
})

Not Supported:

# Using frozen dictionaries or immutable configurations
from types import MappingProxyType
config = MappingProxyType({
    'bootstrap.servers': 'localhost:9092'
})
producer = KafkaProducer(**config)

Why This Matters

The Superstream library needs to modify your producer's configuration to apply optimizations based on your cluster's characteristics. This includes adjusting settings like compression, batch size, and other performance parameters. When the configuration is immutable, these optimizations cannot be applied.

Installation

pip install superclient && python -m superclient install_pth

That's it! Superclient will now automatically load and optimize all Kafka producers in your Python environment.

Usage

After installation, superclient works automatically. Just use your Kafka clients as usual:

# kafka-python
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='localhost:9092')
# Automatically optimized!

# confluent-kafka
from confluent_kafka import Producer
producer = Producer({'bootstrap.servers': 'localhost:9092'})
# Automatically optimized!

# aiokafka
from aiokafka import AIOKafkaProducer
producer = AIOKafkaProducer(bootstrap_servers='localhost:9092')
# Automatically optimized!

Docker Integration

When using Superstream Clients with containerized applications, include the package in your Dockerfile:

FROM python:3.8-slim

# Install superclient
RUN pip install superclient
RUN python -m superclient install_pth

# Your application code
COPY . /app
WORKDIR /app

# Run your application
CMD ["python", "your_app.py"]

Required Environment Variables

  • SUPERSTREAM_TOPICS_LIST: Comma-separated list of topics your application produces to

Optional Environment Variables

  • SUPERSTREAM_LATENCY_SENSITIVE: Set to "true" to prevent any modification to linger.ms values
  • SUPERSTREAM_DISABLED: Set to "true" to disable optimization
  • SUPERSTREAM_DEBUG: Set to "true" to enable debug logs

Example:

export SUPERSTREAM_TOPICS_LIST=orders,payments,user-events
export SUPERSTREAM_LATENCY_SENSITIVE=true

Prerequisites

  • Python 3.8 or higher
  • Kafka cluster that is connected to the Superstream's console
  • Read and write permissions to the superstream.* topics

License

Apache License 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

superclient_beta-0.1.tar.gz (19.8 kB view details)

Uploaded Source

Built Distributions

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

superclient_beta-0.1.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

superclient_beta-0.1-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file superclient_beta-0.1.tar.gz.

File metadata

  • Download URL: superclient_beta-0.1.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for superclient_beta-0.1.tar.gz
Algorithm Hash digest
SHA256 242060eda01206c5931f92dea24756a1f831b9d279a98e048c7a46867791637f
MD5 fd7aa98b9ea9258d98b6a8e76deac1c1
BLAKE2b-256 f069f8a65fd39884a85a860c0933c7c15dcc9be392deeb4ddbd8227daa38af82

See more details on using hashes here.

File details

Details for the file superclient_beta-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for superclient_beta-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6eaa69076a82caa1463d000556094381377b2a102385e26f6be2bb7b9de1bcd9
MD5 7b629cefb2d3d6f91704198bb597ae7c
BLAKE2b-256 4431bd1140740f9c4aad549f42f395283f3d641fdfb48b7b3a0d8080adbda9c8

See more details on using hashes here.

File details

Details for the file superclient_beta-0.1-py3-none-any.whl.

File metadata

  • Download URL: superclient_beta-0.1-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for superclient_beta-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 587b9a39c041174aa0d998153f8182e4fda60b87a71385ff6ec8048679a6960a
MD5 d17b08e9a0e6995f8ff206b64be37e69
BLAKE2b-256 ae2292ffee7f9b76d99f77790cea996c9b4380c8b487b7317795dad312f085d7

See more details on using hashes here.

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