Skip to main content

GitHub license Python Version Build Status PyPI version

faust-s3-backed-serializer

A Faust Serializer that reads and writes records from and to S3 transparently.

This serializer is compatible with our Kafka S3-backed SerDe for Java.

Read more about it on our blog.

Getting Started

PyPi

pip install faust-s3-backed-serializer
Usage

The serializer was build to be used with other serializers. The idea is to use the "concatenation" feature that comes with Faust

import faust
from faust import Record
import logging
from faust_s3_backed_serializer import S3BackedSerializer
from faust.serializers import codecs


# model.user
class UserModel(Record, serializer="s3_json"):
    first_name: str
    last_name: str


# Declare the serializers
credentials = { 
# you can also leave the fields empty 
# in order to use the default AWS credential chain
    's3backed.access.key': 'access_key',
    's3backed.secret.key': 'secret_key'
}

topic_name = "users_s3"
s3_backed_serializer = S3BackedSerializer(output_topic=topic_name,
                                          base_path="s3://your-bucket-name/",
                                          region_name="eu-central-1",
                                          s3_credentials=credentials, 
                                          max_size=0,
                                          is_key=False)
json_serializer = codecs.get_codec("json")

# Here we use json as the first serializer and
# then we can upload everything to the S3 bucket
s3_json_serializer = json_serializer | s3_backed_serializer

# config
logger = logging.getLogger(__name__)
codecs.register("s3_json", s3_json_serializer)
app = faust.App("app_id", broker="kafka://localhost:9092")
users_topic = app.topic(topic_name, value_type=UserModel)


@app.agent(users_topic)
async def users(users):
    async for user in users:
        logger.info("Event received in topic")
        logger.info(f"The user is : {user}")


@app.timer(5.0, on_leader=True)
async def send_users():
    data_user = {"first_name": "bar", "last_name": "foo"}
    user = UserModel(**data_user)
    await users.send(value=user, value_serializer=s3_json_serializer)


app.main()

Contributing

We are happy if you want to contribute to this project. If you find any bugs or have suggestions for improvements, please open an issue. We are also happy to accept your PRs. Just open an issue beforehand and let us know what you want to do and why.

License

This project is licensed under the MIT license. Have a look at the LICENSE for more details.

Metadata

Release files for faust-s3-backed-serializer 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for faust-s3-backed-serializer 1.1.0
File Size Uploaded
faust-s3-backed-serializer-1.1.0.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for faust-s3-backed-serializer 1.1.0
File Interpreter ABI Platform
faust_s3_backed_serializer-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / faust-s3-backed-serializer-1.1.0.tar.gz

Download URL faust-s3-backed-serializer-1.1.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
315c4c05b96be9702fdb2768f931c9ce87ce3197ac6b5a6680c396fec41a6be8
BLAKE2b-256 checksum
How to use checksums
450c003b5716a8d7e247f6b233b7e8ac81d63c88dea2c99b2adfda88a8ee70b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / faust_s3_backed_serializer-1.1.0-py3-none-any.whl

Download URL faust_s3_backed_serializer-1.1.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86d2e0a2981beae8d5f866ae95ed8212171dc21e4033c42d2c06677cf1fdbe4d
BLAKE2b-256 checksum
How to use checksums
68f1dc425aa802235b7c52a91d3aa459e9628c9f637b4b74b3a0b24cd7a38230
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page