High level Python API for writing to Kafka
Welcome to Py2k
A high level Python to Kafka API with Schema Registry compatibility and automatic avro schema creation.
- Free software: Apache2 license
Py2K is currently available on PIP:
pip install py2k
You can view additional documentation on our website.
Please see the Contribution Guide for more information.
from py2k.record import PandasToRecordsTransformer from py2k.writer import KafkaWriter # assuming we have a pandas DataFrame, df records = PandasToRecordsTransformer(df=df, record_name='test_model').from_pandas() writer = KafkaWriter( topic="topic_name", schema_registry_config=schema_registry_config, producer_config=producer_config ) writer.write(records)
For additional examples please see the examples folder
- Schema Registry Integration
- Automatic Avro Serialization from pandas DataFrames
- Automatic Avro Schema generation from pandas DataFrames and Pydantic objects
Copyright 2021 ABSA Group Limited Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- User can choose whether to return list (from_pandas) or iterator (iter_from_pandas)
- KafkaWriter was adjusted accordingly to accept any iterable in it's write method
- Resolved boolean schema not being converted to the correct avro schema values PR #48 - @vesely-david
- Adhering to Kafka and Avro parlance by renaming:
- models module -> record
- KafkaModel -> KafkaRecord
- DynamicPandasModel -> PandasToRecordsTransformer
- item -> record
- Move schema knowledge to KafkaRecord
__key_fields__in KafkaRecord to enable specifying which fields are part of the key
__include_key__in KafkaRecord to enable specifying whether key_fields should be part of the value message
Big thank you to @vesely-david for this change
- Minor API change for easier dynamic creation of KafkaModels from a pandas DataFrame
- First commit on Github.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.