This release is a pre-release and may not be stable for production use.
Heizer
A python library to easily create kafka producer and consumer
Install
pip install heizer
Setup
Use docker-compose.yaml file to start kafka service
docker-compose up -d
Sample
Producer
from heizer import HeizerConfig, HeizerTopic, producer
producer_config = HeizerConfig(
{
"bootstrap.servers": "localhost:9092",
}
)
my_topics = [
HeizerTopic(name="my.topic1", partitions=[0]),
HeizerTopic(name="my.topic2", partitions=[0, 1]),
]
@producer(
topics=my_topics,
config=producer_config,
)
def my_producer(my_name: str):
return {
"name": my_name
}
if __name__ == "__main__":
my_producer("Jack")
my_producer("Alice")
Consumer
from heizer import HeizerConfig, HeizerTopic, consumer, producer
from confluent_kafka import Message
import json
producer_config = HeizerConfig(
{
"bootstrap.servers": "localhost:9092",
}
)
consumer_config = HeizerConfig(
{
"bootstrap.servers": "localhost:9092",
"group.id": "default",
"auto.offset.reset": "earliest",
}
)
topics = [HeizerTopic(name="my.topic1")]
@producer(
topics=topics,
config=producer_config
)
def produce_data(status: str, result: str):
return {
"status": status,
"result": result,
}
# Heizer expects consumer stopper func return Bool type result
# For this example, consumer will stop and return value if
# `status` is `success` in msg
# If there is no stopper func, consumer will keep running forever
def stopper(msg: Message):
data = json.loads(msg.value().decode("utf-8"))
if data["status"] == "success":
return True
return False
@consumer(
topics=topics,
config=consumer_config,
stopper=stopper,
)
def consume_data(message):
data = json.loads(message.value().decode("utf-8"))
print(data)
return data["result"]
if __name__ == "__main__":
produce_data("start", "1")
produce_data("loading", "2")
produce_data("success", "3")
produce_data("postprocess", "4")
result = consume_data()
print("Expected Result:", result)
After you executed this code block, you will see those output on your terminal
{'status': 'start', 'result': '1'}
{'status': 'loading', 'result': '2'}
{'status': 'success', 'result': '3'}
Expected Result: 3
Metadata
Release files for heizer 999999.dev1679769565
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 |
|---|---|---|---|---|
| heizer-999999.dev1679769565.tar.gz | 662.7 kB | Without provenance | Details for heizer-999999.dev1679769565.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| heizer-999999.dev1679769565-py3-none-any.whl | Python 3 | none | any | Details for heizer-999999.dev1679769565-py3-none-any.whl |
Total release size: 695.8 kB
Release files / heizer-999999.dev1679769565.tar.gz
| Download URL | heizer-999999.dev1679769565.tar.gz |
|---|---|
| Size | 662.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d35bb06a610b6afe83ad83009ad8427f9c870ef3e056db9948d88797f0703a3b
|
|
BLAKE2b-256 checksum How to use checksums |
3a12605f83db6d3835ae2bb918c604ffbab82b8423fb3db7c358c24d0570daf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / heizer-999999.dev1679769565-py3-none-any.whl
| Download URL | heizer-999999.dev1679769565-py3-none-any.whl |
|---|---|
| Size | 33.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3dc9af7d952ece731cdb12f5d086537408480f50f6e7ca51834d59a0ccbcf973
|
|
BLAKE2b-256 checksum How to use checksums |
30f15944ec7ffff19320dfc791b0a2ccb99e4a4fcb28edb6bd5d87c657182dd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for heizer 999999.dev1679769565
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.