openframe-adapters-queue-kafka 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,221 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
219
+
220
+ # Miscellaneous
221
+ .DS_Store
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.4
2
+ Name: openframe-adapters-queue-kafka
3
+ Version: 1.1.0
4
+ Summary: OpenFrame Microservice Suite - Apache Kafka queue adapter.
5
+ Project-URL: Homepage, https://github.com/Furious-Meteors/openframe-adapters
6
+ Project-URL: Documentation, https://furious-meteors.github.io/openframe-adapters/
7
+ Project-URL: Repository, https://github.com/Furious-Meteors/openframe-adapters
8
+ Project-URL: Changelog, https://github.com/Furious-Meteors/openframe-adapters/blob/production/.github/CHANGELOG.md
9
+ Project-URL: Bug Tracker, https://github.com/Furious-Meteors/openframe-adapters/issues
10
+ Author-email: Furious Meteors Engineering <engineering@furiousmeteors.dev>
11
+ Maintainer-email: Furious Meteors Engineering <engineering@furiousmeteors.dev>
12
+ License: MIT
13
+ Keywords: hexagonal,kafka,messaging,microservice,openframe,queue
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Topic :: System :: Distributed Computing
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11
26
+ Requires-Dist: aiokafka>=0.11
27
+ Requires-Dist: openframe-core<3,>=2.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
30
+ Requires-Dist: pytest-mock>=3.14; extra == 'dev'
31
+ Requires-Dist: pytest>=8.0; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # openframe-adapters-queue-kafka
35
+
36
+ Apache Kafka queue adapter for the **OpenFrame Microservice Development Suite**.
37
+
38
+ Part of the [`openframe-adapters`](https://github.com/Furious-Meteors/openframe-adapters) monorepo.
39
+
40
+ ---
41
+
42
+ ## What it provides
43
+
44
+ | Symbol | Purpose |
45
+ |---|---|
46
+ | `KafkaSettings` | Pydantic-settings subclass — reads all config from env vars |
47
+ | `KafkaProducer[T]` | Generic async message producer — `BaseProducer[T]` |
48
+ | `KafkaConsumer[T]` | Generic async message consumer — `BaseConsumer[T]` |
49
+ | `KafkaPlugin` | `OpenFramePlugin` — structured lifecycle via `PluginRegistry` |
50
+
51
+ ## Installation
52
+
53
+ ```bash
54
+ # Via meta-package (recommended)
55
+ pip install "openframe-adapters[kafka]"
56
+
57
+ # Or directly
58
+ pip install openframe-adapters-queue-kafka
59
+ ```
60
+
61
+ ## Quick start
62
+
63
+ ```python
64
+ from openframe.adapters.queue.kafka import KafkaSettings, KafkaProducer, KafkaConsumer
65
+
66
+ settings = KafkaSettings(kafka_bootstrap_servers="localhost:9092")
67
+
68
+ # Produce
69
+ producer = KafkaProducer(settings)
70
+ await producer.start()
71
+ await producer.publish({"event": "item.created", "id": "abc"})
72
+ await producer.publish_batch([{"event": "x"}, {"event": "y"}])
73
+ await producer.close()
74
+
75
+ # Consume
76
+ consumer = KafkaConsumer(settings)
77
+
78
+ async def handle(event: dict) -> None:
79
+ print(f"Received: {event}")
80
+
81
+ await consumer.subscribe(handle) # runs until consumer.close() called
82
+ ```
83
+
84
+ ## Configuration
85
+
86
+ | Env var | Default | Description |
87
+ |---|---|---|
88
+ | `KAFKA_BOOTSTRAP_SERVERS` | **required** | `host:port,host:port` |
89
+ | `KAFKA_TOPIC` | `"openframe"` | Default topic for producer and consumer |
90
+ | `KAFKA_GROUP_ID` | `"openframe-group"` | Consumer group ID |
91
+ | `KAFKA_AUTO_OFFSET_RESET` | `"earliest"` | `"earliest"` or `"latest"` |
92
+ | `KAFKA_MAX_POLL_RECORDS` | `10` | Max messages per poll |
93
+ | `KAFKA_SESSION_TIMEOUT_MS` | `30000` | Consumer session timeout |
94
+ | `KAFKA_REQUEST_TIMEOUT_MS` | `30000` | Broker request timeout |
95
+ | `KAFKA_SECURITY_PROTOCOL` | `"PLAINTEXT"` | `"PLAINTEXT"`, `"SSL"`, `"SASL_PLAINTEXT"` |
96
+ | `KAFKA_SASL_MECHANISM` | `""` | `"PLAIN"`, `"SCRAM-SHA-256"`, etc. |
97
+ | `KAFKA_SASL_USERNAME` | `""` | SASL username |
98
+ | `KAFKA_SASL_PASSWORD` | `""` | SASL password |
99
+
100
+ ## Typed domain objects
101
+
102
+ ```python
103
+ from openframe.adapters.queue.kafka import KafkaProducer, KafkaConsumer, KafkaSettings
104
+ from dataclasses import dataclass, asdict
105
+
106
+ @dataclass
107
+ class OrderEvent:
108
+ order_id: str
109
+ event_type: str
110
+
111
+ class OrderProducer(KafkaProducer[OrderEvent]):
112
+ def _serialise(self, message: OrderEvent) -> bytes:
113
+ import json
114
+ return json.dumps(asdict(message)).encode("utf-8")
115
+
116
+ class OrderConsumer(KafkaConsumer[OrderEvent]):
117
+ def _deserialise(self, raw: bytes) -> OrderEvent:
118
+ import json
119
+ return OrderEvent(**json.loads(raw.decode("utf-8")))
120
+ ```
121
+
122
+ ## Plugin lifecycle (optional)
123
+
124
+ ```python
125
+ from openframe.core.plugins import PluginRegistry
126
+ from openframe.adapters.queue.kafka import KafkaPlugin, KafkaSettings
127
+
128
+ registry = PluginRegistry()
129
+ registry.register(KafkaPlugin(KafkaSettings()))
130
+ await registry.initialize_all()
131
+
132
+ plugin = registry.get("queue")
133
+ producer = plugin.get_producer()
134
+ await producer.publish({"event": "item.created"})
135
+
136
+ consumer = plugin.make_consumer()
137
+ await consumer.subscribe(handler)
138
+ ```
139
+
140
+ ## Consumer acknowledgement semantics
141
+
142
+ | Outcome | Behaviour |
143
+ |---|---|
144
+ | Handler returns | `ack()` called → offset committed → message consumed |
145
+ | Handler raises | `nack()` called → no commit → message redelivered |
146
+ | `consumer.close()` | polling loop exits → consumer stopped cleanly |
147
+
148
+ ## License
149
+
150
+ MIT — © Furious Meteors Engineering
@@ -0,0 +1,117 @@
1
+ # openframe-adapters-queue-kafka
2
+
3
+ Apache Kafka queue adapter for the **OpenFrame Microservice Development Suite**.
4
+
5
+ Part of the [`openframe-adapters`](https://github.com/Furious-Meteors/openframe-adapters) monorepo.
6
+
7
+ ---
8
+
9
+ ## What it provides
10
+
11
+ | Symbol | Purpose |
12
+ |---|---|
13
+ | `KafkaSettings` | Pydantic-settings subclass — reads all config from env vars |
14
+ | `KafkaProducer[T]` | Generic async message producer — `BaseProducer[T]` |
15
+ | `KafkaConsumer[T]` | Generic async message consumer — `BaseConsumer[T]` |
16
+ | `KafkaPlugin` | `OpenFramePlugin` — structured lifecycle via `PluginRegistry` |
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ # Via meta-package (recommended)
22
+ pip install "openframe-adapters[kafka]"
23
+
24
+ # Or directly
25
+ pip install openframe-adapters-queue-kafka
26
+ ```
27
+
28
+ ## Quick start
29
+
30
+ ```python
31
+ from openframe.adapters.queue.kafka import KafkaSettings, KafkaProducer, KafkaConsumer
32
+
33
+ settings = KafkaSettings(kafka_bootstrap_servers="localhost:9092")
34
+
35
+ # Produce
36
+ producer = KafkaProducer(settings)
37
+ await producer.start()
38
+ await producer.publish({"event": "item.created", "id": "abc"})
39
+ await producer.publish_batch([{"event": "x"}, {"event": "y"}])
40
+ await producer.close()
41
+
42
+ # Consume
43
+ consumer = KafkaConsumer(settings)
44
+
45
+ async def handle(event: dict) -> None:
46
+ print(f"Received: {event}")
47
+
48
+ await consumer.subscribe(handle) # runs until consumer.close() called
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ | Env var | Default | Description |
54
+ |---|---|---|
55
+ | `KAFKA_BOOTSTRAP_SERVERS` | **required** | `host:port,host:port` |
56
+ | `KAFKA_TOPIC` | `"openframe"` | Default topic for producer and consumer |
57
+ | `KAFKA_GROUP_ID` | `"openframe-group"` | Consumer group ID |
58
+ | `KAFKA_AUTO_OFFSET_RESET` | `"earliest"` | `"earliest"` or `"latest"` |
59
+ | `KAFKA_MAX_POLL_RECORDS` | `10` | Max messages per poll |
60
+ | `KAFKA_SESSION_TIMEOUT_MS` | `30000` | Consumer session timeout |
61
+ | `KAFKA_REQUEST_TIMEOUT_MS` | `30000` | Broker request timeout |
62
+ | `KAFKA_SECURITY_PROTOCOL` | `"PLAINTEXT"` | `"PLAINTEXT"`, `"SSL"`, `"SASL_PLAINTEXT"` |
63
+ | `KAFKA_SASL_MECHANISM` | `""` | `"PLAIN"`, `"SCRAM-SHA-256"`, etc. |
64
+ | `KAFKA_SASL_USERNAME` | `""` | SASL username |
65
+ | `KAFKA_SASL_PASSWORD` | `""` | SASL password |
66
+
67
+ ## Typed domain objects
68
+
69
+ ```python
70
+ from openframe.adapters.queue.kafka import KafkaProducer, KafkaConsumer, KafkaSettings
71
+ from dataclasses import dataclass, asdict
72
+
73
+ @dataclass
74
+ class OrderEvent:
75
+ order_id: str
76
+ event_type: str
77
+
78
+ class OrderProducer(KafkaProducer[OrderEvent]):
79
+ def _serialise(self, message: OrderEvent) -> bytes:
80
+ import json
81
+ return json.dumps(asdict(message)).encode("utf-8")
82
+
83
+ class OrderConsumer(KafkaConsumer[OrderEvent]):
84
+ def _deserialise(self, raw: bytes) -> OrderEvent:
85
+ import json
86
+ return OrderEvent(**json.loads(raw.decode("utf-8")))
87
+ ```
88
+
89
+ ## Plugin lifecycle (optional)
90
+
91
+ ```python
92
+ from openframe.core.plugins import PluginRegistry
93
+ from openframe.adapters.queue.kafka import KafkaPlugin, KafkaSettings
94
+
95
+ registry = PluginRegistry()
96
+ registry.register(KafkaPlugin(KafkaSettings()))
97
+ await registry.initialize_all()
98
+
99
+ plugin = registry.get("queue")
100
+ producer = plugin.get_producer()
101
+ await producer.publish({"event": "item.created"})
102
+
103
+ consumer = plugin.make_consumer()
104
+ await consumer.subscribe(handler)
105
+ ```
106
+
107
+ ## Consumer acknowledgement semantics
108
+
109
+ | Outcome | Behaviour |
110
+ |---|---|
111
+ | Handler returns | `ack()` called → offset committed → message consumed |
112
+ | Handler raises | `nack()` called → no commit → message redelivered |
113
+ | `consumer.close()` | polling loop exits → consumer stopped cleanly |
114
+
115
+ ## License
116
+
117
+ MIT — © Furious Meteors Engineering
@@ -0,0 +1 @@
1
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
@@ -0,0 +1 @@
1
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
@@ -0,0 +1 @@
1
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
@@ -0,0 +1,49 @@
1
+ """
2
+ openframe.adapters.queue.kafka
3
+ ================================
4
+ Apache Kafka queue adapter for the OpenFrame Microservice Suite.
5
+
6
+ Public API::
7
+
8
+ KafkaSettings — Pydantic Settings subclass for connection config.
9
+ KafkaProducer — Generic async message producer (BaseProducer[T]).
10
+ KafkaConsumer — Generic async message consumer (BaseConsumer[T]).
11
+ KafkaPlugin — OpenFramePlugin implementation for PluginRegistry.
12
+
13
+ Quick start::
14
+
15
+ from openframe.adapters.queue.kafka import (
16
+ KafkaSettings,
17
+ KafkaProducer,
18
+ KafkaConsumer,
19
+ )
20
+
21
+ settings = KafkaSettings(kafka_bootstrap_servers="localhost:9092")
22
+
23
+ # Produce
24
+ producer = KafkaProducer(settings)
25
+ await producer.start()
26
+ await producer.publish({"event": "item.created", "id": "abc"})
27
+ await producer.close()
28
+
29
+ # Consume
30
+ consumer = KafkaConsumer(settings)
31
+
32
+ async def handle(event: dict) -> None:
33
+ print(f"Received: {event}")
34
+
35
+ await consumer.subscribe(handle)
36
+ """
37
+ from __future__ import annotations
38
+
39
+ from .config import KafkaSettings
40
+ from .consumer import KafkaConsumer
41
+ from .plugin import KafkaPlugin
42
+ from .producer import KafkaProducer
43
+
44
+ __all__ = [
45
+ "KafkaSettings",
46
+ "KafkaProducer",
47
+ "KafkaConsumer",
48
+ "KafkaPlugin",
49
+ ]
@@ -0,0 +1,51 @@
1
+ """
2
+ openframe/adapters/queue/kafka/config.py
3
+ ==========================================
4
+ Settings for the Kafka queue adapter, sourced from environment variables
5
+ via ``openframe-core``'s ``BaseAdapterSettings`` (pydantic-settings).
6
+
7
+ Required env vars:
8
+ KAFKA_BOOTSTRAP_SERVERS: Comma-separated broker list.
9
+ Format: host:port,host:port
10
+
11
+ Optional env vars (all have defaults):
12
+ KAFKA_TOPIC: str = "openframe" — default topic
13
+ KAFKA_GROUP_ID: str = "openframe-group" — consumer group
14
+ KAFKA_AUTO_OFFSET_RESET: str = "earliest"
15
+ KAFKA_MAX_POLL_RECORDS: int = 10
16
+ KAFKA_SESSION_TIMEOUT_MS: int = 30000
17
+ KAFKA_REQUEST_TIMEOUT_MS: int = 30000
18
+ KAFKA_SECURITY_PROTOCOL: str = "PLAINTEXT"
19
+ KAFKA_SASL_MECHANISM: str = ""
20
+ KAFKA_SASL_USERNAME: str = ""
21
+ KAFKA_SASL_PASSWORD: str = ""
22
+ ADAPTER_NAME: str = "kafka"
23
+ """
24
+ from __future__ import annotations
25
+
26
+ from openframe.core.config import BaseAdapterSettings
27
+
28
+ __all__ = ["KafkaSettings"]
29
+
30
+
31
+ class KafkaSettings(BaseAdapterSettings):
32
+ """
33
+ Pydantic-settings subclass for the Kafka queue adapter.
34
+
35
+ All fields are read from environment variables with the exact names
36
+ shown above. ``BaseAdapterSettings`` provides ``operation_timeout``
37
+ (default 30.0 s) and ``connection_timeout`` (default 30.0 s).
38
+ """
39
+
40
+ kafka_bootstrap_servers: str
41
+ kafka_topic: str = "openframe"
42
+ kafka_group_id: str = "openframe-group"
43
+ kafka_auto_offset_reset: str = "earliest"
44
+ kafka_max_poll_records: int = 10
45
+ kafka_session_timeout_ms: int = 30_000
46
+ kafka_request_timeout_ms: int = 30_000
47
+ kafka_security_protocol: str = "PLAINTEXT"
48
+ kafka_sasl_mechanism: str = ""
49
+ kafka_sasl_username: str = ""
50
+ kafka_sasl_password: str = ""
51
+ adapter_name: str = "kafka"