Kaf
Så er det tid til en kop kaf'
Kaf is a small Python framework for creating Kafka apps. It is inspired by Faust, but differs in the following ways:
- Kaf is synchronous (async is future work)
- Kaf is compatible with Azure Eventhubs (over Kafka interface)
- Kaf is designed to work with different brokers for the consumer and producer
The framework depends on Confluent Kafka.
How to use
Minimal example:
import logging
from kaf import KafkaApp
consumer_config = {'bootstrap.servers': 'kafka:9092', 'group.id': 'myapp'}
producer_config = {'bootstrap.servers': 'kafka:9092'}
app = KafkaApp(
'myapp',
consumer_config=consumer_config,
producer_config=producer_config,
consumer_timeout=5,
consumer_batch_size=1
)
app.logger.setLevel(logging.INFO)
@app.process(topic='foo', publish_to='bar', accepts='json', returns='json')
def add_one(input):
number = input['number']
yield {'result': number+1}, bytes(number)
@app.on_processed
def done(msg, seconds_elapsed):
app.logger.info(f'Processed message in {seconds_elapsed} seconds')
if __name__ == '__main__':
app.run()
How errors are handled
Kafka functions keep trying until they succeed. Each user function will get one chance to process each incoming message. Any exception raised by a user functions will only be logged, but otherwise ignored. If a user wants to implement retrying they can do that, but it will stall the pipeline until the function returns.
Future work:
Features to be added:
- Add decorators for app events
on_consume,on_processedandon_publised. This will allow to hook up e.g. Datadog metrics to these events.
How to deploy a new version
Steps (can maybe be improved):
- change version and download_url in setup.py
- git add + commit + push
- create new release in GitHub (check source-code link, should match download_url)
- Run
python setup.py sdist - Run
twine upload dist/* --verbose(if not installed,pip install twinefirst)
Useful links used:
Metadata
Release files for kaf 0.2.3
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 |
|---|---|---|---|---|
| kaf-0.2.3.tar.gz | 5.7 kB | Without provenance | Details for kaf-0.2.3.tar.gz |
Release files / kaf-0.2.3.tar.gz
| Download URL | kaf-0.2.3.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d900ada4f7e8eeccd31d3bff9c38003b3a27d80c9b01318a9979bad67a63bba0
|
|
BLAKE2b-256 checksum How to use checksums |
01f5b329cdc1085c4108288836566ef03404c6da799aa19969d9377dd8fdbe3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.7
|
Security for kaf 0.2.3
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.