Skip to main content

amgi-kafka-event-source-mapping

amgi-kafka-event-source-mapping is an adaptor for AMGI applications to run in a Kafka event source mapped environment.

Installation

pip install amgi-kafka-event-source-mapping==0.45.1

Example

This example uses AsyncFast:

from dataclasses import dataclass

from amgi_kafka_event_source_mapping import KafkaEventSourceMappingHandler
from asyncfast import AsyncFast

app = AsyncFast()


@dataclass
class Order:
    item_ids: list[str]


@app.channel("orders")
async def orders(order: Order) -> None:
    # Makes an order
    ...


handler = KafkaEventSourceMappingHandler(app)

What it does

  • Converts Kafka batch events into AMGI message.receive events
  • Uses the Kafka topic name as the AMGI message address
  • Supports partial batch failures so only failed records are reported
  • Sends outbound messages to Kafka using an async producer
  • Outbound messages are sent via the same Kafka broker (bootstrap servers) that the records were received from
  • Optionally manages application startup and shutdown via AMGI lifespan

Record handling

  • Record values and keys are passed to your app as bytes
  • Kafka record headers become AMGI headers
  • Records are only acknowledged when your app emits message.ack
  • Records that emit message.nack or are not acknowledged are treated as failures

Nack handling

By default, records that are negatively acknowledged, or not acknowledged are logged:

handler = KafkaEventSourceMappingHandler(app, on_nack="log")

To fail the invocation when any record is nacked, configure the handler to raise an error instead:

handler = KafkaEventSourceMappingHandler(app, on_nack="error")

This is useful when running in environments where a failed invocation should trigger a retry, or alert.

When using this mode, handlers must be idempotent. Kafka event source mappings may re-deliver records after failures, restarts, or rebalances, and your application logic should be safe to execute more than once for the same record.

Lifespan

Lifespan support is enabled by default.

  • Startup runs once per Lambda execution environment
  • Shutdown is attempted when the environment is terminated

Shutdown handling relies on signal.SIGTERM, which is supported by Python 3.12 and later Lambda runtimes.

To use fully stateless, per-invocation behavior, disable lifespan:

handler = KafkaEventSourceMappingHandler(app, lifespan=False)

Contact

For questions or suggestions, please contact jack.burridge@mail.com.

License

Copyright 2026 AMGI

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amgi_kafka_event_source_mapping-0.45.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file amgi_kafka_event_source_mapping-0.45.1.tar.gz.

File metadata

  • Download URL: amgi_kafka_event_source_mapping-0.45.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for amgi_kafka_event_source_mapping-0.45.1.tar.gz
Algorithm Hash digest
SHA256 75353fefb9ac5c29405feba958708f3016ea5d28f9dd9205d916a817f3b0add8
MD5 68538604ea8be2b5127ad620dfc66c25
BLAKE2b-256 6ad42f161bf119e5eaa38b558e5f6a39b60b2470d083e7d9a06d05689924b107

See more details on using hashes here.

File details

Details for the file amgi_kafka_event_source_mapping-0.45.1-py3-none-any.whl.

File metadata

  • Download URL: amgi_kafka_event_source_mapping-0.45.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for amgi_kafka_event_source_mapping-0.45.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc51c3157f872df8cca4eff419de3509ed175e0d700af7dece37d37a84a4e4ab
MD5 9221a16574f4a7fec24b776fc15c473c
BLAKE2b-256 ab3dd171730773c442bdf5a41c457e1a6cb3a64433ee06deb77276ecfc19f2aa

See more details on using hashes here.

Release history Release notifications | RSS feed

0.47.0

2 files

0.46.0

2 files

This release

0.45.1 This release

2 files

0.45.0

2 files

0.44.0

2 files

0.43.0

2 files

0.42.0

2 files

0.41.1

2 files

0.41.0

2 files

0.40.0

2 files

0.39.0

2 files

0.38.0

2 files

0.37.0

2 files

0.36.0

2 files

0.35.0

2 files

0.34.0

2 files

0.33.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page