celery-salt 1.0.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.
- celery_salt-1.0.0/LICENSE +21 -0
- celery_salt-1.0.0/PKG-INFO +260 -0
- celery_salt-1.0.0/README.md +225 -0
- celery_salt-1.0.0/celery_salt/__init__.py +26 -0
- celery_salt-1.0.0/celery_salt/core/__init__.py +26 -0
- celery_salt-1.0.0/celery_salt/core/decorators.py +677 -0
- celery_salt-1.0.0/celery_salt/core/exceptions.py +89 -0
- celery_salt-1.0.0/celery_salt/core/registry.py +112 -0
- celery_salt-1.0.0/celery_salt/django/__init__.py +10 -0
- celery_salt-1.0.0/celery_salt/django/celery.py +270 -0
- celery_salt-1.0.0/celery_salt/django/decorators.py +302 -0
- celery_salt-1.0.0/celery_salt/django/mixins.py +226 -0
- celery_salt-1.0.0/celery_salt/django/signals.py +134 -0
- celery_salt-1.0.0/celery_salt/integrations/__init__.py +1 -0
- celery_salt-1.0.0/celery_salt/integrations/client.py +75 -0
- celery_salt-1.0.0/celery_salt/integrations/dispatcher.py +265 -0
- celery_salt-1.0.0/celery_salt/integrations/producer.py +384 -0
- celery_salt-1.0.0/celery_salt/integrations/registry.py +124 -0
- celery_salt-1.0.0/celery_salt/logging/__init__.py +9 -0
- celery_salt-1.0.0/celery_salt/logging/formatters.py +84 -0
- celery_salt-1.0.0/celery_salt/logging/handlers.py +92 -0
- celery_salt-1.0.0/celery_salt/metrics/__init__.py +6 -0
- celery_salt-1.0.0/celery_salt/metrics/collectors.py +300 -0
- celery_salt-1.0.0/celery_salt/metrics/exporters.py +242 -0
- celery_salt-1.0.0/celery_salt/utils/__init__.py +17 -0
- celery_salt-1.0.0/celery_salt/utils/error_handling.py +37 -0
- celery_salt-1.0.0/celery_salt/utils/json_encoder.py +111 -0
- celery_salt-1.0.0/celery_salt/utils/response_handler.py +52 -0
- celery_salt-1.0.0/celery_salt/version.py +1 -0
- celery_salt-1.0.0/pyproject.toml +78 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Sigley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: celery-salt
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Event-driven architecture library for Python that extends Celery with event publishing/subscribing patterns
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: celery,messaging,pydantic,django,events,pubsub,broadcast,microservices,event-driven,schema-registry
|
|
8
|
+
Author: David Sigley
|
|
9
|
+
Author-email: djsigley@gmail.com
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Framework :: Celery
|
|
13
|
+
Classifier: Framework :: Django :: 4.0
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Provides-Extra: all
|
|
23
|
+
Provides-Extra: django
|
|
24
|
+
Provides-Extra: protobuf
|
|
25
|
+
Requires-Dist: celery (>=5.3.0,<6.0.0)
|
|
26
|
+
Requires-Dist: django (>=4.0.0,<5.0.0) ; extra == "django" or extra == "all"
|
|
27
|
+
Requires-Dist: kombu (>=5.3.0,<6.0.0)
|
|
28
|
+
Requires-Dist: protobuf (>=4.0.0,<5.0.0) ; extra == "protobuf" or extra == "all"
|
|
29
|
+
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
|
|
30
|
+
Project-URL: Documentation, https://github.com/sigularusrex/celery-salt
|
|
31
|
+
Project-URL: Homepage, https://github.com/sigularusrex/celery-salt
|
|
32
|
+
Project-URL: Repository, https://github.com/sigularusrex/celery-salt
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# CelerySalt
|
|
36
|
+
|
|
37
|
+
A modern, event-driven architecture library for Python that extends Celery with schema-validated event publishing/subscribing patterns. Built with Pydantic for type safety and import-time schema registration.
|
|
38
|
+
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
[](https://www.python.org/downloads/)
|
|
41
|
+
|
|
42
|
+
> **🚀 v1.0.0** - First release! Pydantic-based event schemas, import-time registration, RPC support, and protocol compatibility with tchu-tchu.
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- ✨ **Pydantic-Based Schemas** - Type-safe event definitions with automatic validation
|
|
47
|
+
- 🚀 **Import-Time Registration** - Schemas registered at import time for early error detection
|
|
48
|
+
- 📡 **Broadcast Events** - Fire-and-forget pub/sub messaging (one event → many subscribers)
|
|
49
|
+
- ⚡ **RPC Support** - Synchronous request/response with response/error schema validation
|
|
50
|
+
- 🔄 **Protocol Compatible** - Works with existing tchu-tchu applications
|
|
51
|
+
- 🎯 **Framework Agnostic** - Core library works with any Python app (Django optional)
|
|
52
|
+
- 🛡️ **Schema Registry** - Centralized schema management (in-memory, PostgreSQL, Cloud)
|
|
53
|
+
- 🔁 **Celery Integration** - Full Celery features: retries, time limits, rate limiting, monitoring
|
|
54
|
+
- 📦 **Simple API** - Decorator-based: `@event` and `@subscribe`
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
### Installation
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install celery-salt
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Broadcast Example
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from celerysalt import event, subscribe
|
|
68
|
+
|
|
69
|
+
# Define event schema
|
|
70
|
+
@event("user.signup.completed")
|
|
71
|
+
class UserSignupCompleted:
|
|
72
|
+
user_id: int
|
|
73
|
+
email: str
|
|
74
|
+
company_id: int
|
|
75
|
+
signup_source: str = "web"
|
|
76
|
+
|
|
77
|
+
# Publish event
|
|
78
|
+
UserSignupCompleted.publish(
|
|
79
|
+
user_id=123,
|
|
80
|
+
email="alice@example.com",
|
|
81
|
+
company_id=1,
|
|
82
|
+
signup_source="web"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Subscribe to event
|
|
86
|
+
@subscribe("user.signup.completed")
|
|
87
|
+
def send_welcome_email(data: UserSignupCompleted):
|
|
88
|
+
print(f"Sending welcome email to {data.email}")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### RPC Example
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from celerysalt import event, subscribe, RPCError
|
|
95
|
+
|
|
96
|
+
# Define RPC request/response schemas
|
|
97
|
+
@event("rpc.calculator.add", mode="rpc")
|
|
98
|
+
class CalculatorAddRequest:
|
|
99
|
+
a: float
|
|
100
|
+
b: float
|
|
101
|
+
|
|
102
|
+
@event.response("rpc.calculator.add")
|
|
103
|
+
class CalculatorAddResponse:
|
|
104
|
+
result: float
|
|
105
|
+
operation: str = "add"
|
|
106
|
+
|
|
107
|
+
@event.error("rpc.calculator.add")
|
|
108
|
+
class CalculatorAddError:
|
|
109
|
+
error_code: str
|
|
110
|
+
error_message: str
|
|
111
|
+
|
|
112
|
+
# Handler
|
|
113
|
+
@subscribe("rpc.calculator.add")
|
|
114
|
+
def handle_add(data: CalculatorAddRequest) -> CalculatorAddResponse:
|
|
115
|
+
return CalculatorAddResponse(result=data.a + data.b, operation="add")
|
|
116
|
+
|
|
117
|
+
# Client call
|
|
118
|
+
response = CalculatorAddRequest.call(a=10, b=5, timeout=10)
|
|
119
|
+
print(f"Result: {response.result}") # 15.0
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Architecture
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
Publisher → RabbitMQ Exchange (tchu_events) → Subscribers
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
- **Exchange**: `tchu_events` (topic exchange, protocol compatible)
|
|
129
|
+
- **Routing**: Topic-based with wildcard support (`user.*`, `#`)
|
|
130
|
+
- **Serialization**: JSON with Pydantic validation
|
|
131
|
+
- **Result Backend**: Redis (required for RPC)
|
|
132
|
+
|
|
133
|
+
## Documentation
|
|
134
|
+
|
|
135
|
+
- [Examples](./examples/) - Working examples for broadcast and RPC
|
|
136
|
+
- [Design Document](./CELERYSALT_DESIGN.md) - Full architecture and design
|
|
137
|
+
- [Implementation Context](./IMPLEMENTATION_CONTEXT.md) - Development context
|
|
138
|
+
|
|
139
|
+
## Requirements
|
|
140
|
+
|
|
141
|
+
- Python 3.10+
|
|
142
|
+
- Celery 5.3+
|
|
143
|
+
- RabbitMQ (message broker)
|
|
144
|
+
- Redis (optional, required for RPC)
|
|
145
|
+
|
|
146
|
+
## Installation
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Basic installation
|
|
150
|
+
pip install celery-salt
|
|
151
|
+
|
|
152
|
+
# With Django support
|
|
153
|
+
pip install celery-salt[django]
|
|
154
|
+
|
|
155
|
+
# With all extras
|
|
156
|
+
pip install celery-salt[all]
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Examples
|
|
160
|
+
|
|
161
|
+
See the [examples](./examples/) directory for complete working examples:
|
|
162
|
+
|
|
163
|
+
- [Basic Broadcast](./examples/basic_broadcast/) - Pub/sub messaging
|
|
164
|
+
- [Basic RPC](./examples/basic_rpc/) - Request/response pattern
|
|
165
|
+
|
|
166
|
+
Run examples with Docker Compose:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
cd examples
|
|
170
|
+
docker-compose up -d # Starts RabbitMQ and Redis
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Key Concepts
|
|
174
|
+
|
|
175
|
+
### Event Schemas
|
|
176
|
+
|
|
177
|
+
Schemas are defined using Pydantic models and registered at import time:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
@event("user.created")
|
|
181
|
+
class UserCreated:
|
|
182
|
+
user_id: int
|
|
183
|
+
email: str
|
|
184
|
+
created_at: datetime
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Publishing Events
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
# Broadcast (fire-and-forget)
|
|
191
|
+
UserCreated.publish(user_id=123, email="user@example.com", created_at=datetime.now())
|
|
192
|
+
|
|
193
|
+
# RPC (synchronous)
|
|
194
|
+
response = CalculatorAddRequest.call(a=10, b=5, timeout=10)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Subscribing to Events
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
@subscribe("user.created")
|
|
201
|
+
def handle_user_created(data: UserCreated):
|
|
202
|
+
# Process event
|
|
203
|
+
pass
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### RPC Response Validation
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
@event.response("rpc.calculator.add")
|
|
210
|
+
class CalculatorAddResponse:
|
|
211
|
+
result: float
|
|
212
|
+
|
|
213
|
+
@event.error("rpc.calculator.add")
|
|
214
|
+
class CalculatorAddError:
|
|
215
|
+
error_code: str
|
|
216
|
+
error_message: str
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Protocol Compatibility
|
|
220
|
+
|
|
221
|
+
CelerySalt maintains protocol compatibility with `tchu-tchu`:
|
|
222
|
+
- Same exchange name: `tchu_events`
|
|
223
|
+
- Same message format: `_tchu_meta` field
|
|
224
|
+
- Same routing key conventions
|
|
225
|
+
|
|
226
|
+
This allows gradual migration: apps using `celery-salt` can communicate with apps still using `tchu-tchu`.
|
|
227
|
+
|
|
228
|
+
## Development
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Clone repository
|
|
232
|
+
git clone https://github.com/sigularusrex/celery-salt.git
|
|
233
|
+
cd celery-salt
|
|
234
|
+
|
|
235
|
+
# Install development dependencies
|
|
236
|
+
pip install -e ".[dev]"
|
|
237
|
+
|
|
238
|
+
# Run tests
|
|
239
|
+
pytest
|
|
240
|
+
|
|
241
|
+
# Run examples
|
|
242
|
+
cd examples
|
|
243
|
+
docker-compose up -d
|
|
244
|
+
celery -A basic_broadcast.subscriber worker --loglevel=info
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT License - see [LICENSE](./LICENSE) file for details.
|
|
250
|
+
|
|
251
|
+
## Contributing
|
|
252
|
+
|
|
253
|
+
Contributions welcome! Please open an issue or pull request on GitHub.
|
|
254
|
+
|
|
255
|
+
## Links
|
|
256
|
+
|
|
257
|
+
- **GitHub**: https://github.com/sigularusrex/celery-salt
|
|
258
|
+
- **Documentation**: https://github.com/sigularusrex/celery-salt
|
|
259
|
+
- **Issues**: https://github.com/sigularusrex/celery-salt/issues
|
|
260
|
+
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# CelerySalt
|
|
2
|
+
|
|
3
|
+
A modern, event-driven architecture library for Python that extends Celery with schema-validated event publishing/subscribing patterns. Built with Pydantic for type safety and import-time schema registration.
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.python.org/downloads/)
|
|
7
|
+
|
|
8
|
+
> **🚀 v1.0.0** - First release! Pydantic-based event schemas, import-time registration, RPC support, and protocol compatibility with tchu-tchu.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- ✨ **Pydantic-Based Schemas** - Type-safe event definitions with automatic validation
|
|
13
|
+
- 🚀 **Import-Time Registration** - Schemas registered at import time for early error detection
|
|
14
|
+
- 📡 **Broadcast Events** - Fire-and-forget pub/sub messaging (one event → many subscribers)
|
|
15
|
+
- ⚡ **RPC Support** - Synchronous request/response with response/error schema validation
|
|
16
|
+
- 🔄 **Protocol Compatible** - Works with existing tchu-tchu applications
|
|
17
|
+
- 🎯 **Framework Agnostic** - Core library works with any Python app (Django optional)
|
|
18
|
+
- 🛡️ **Schema Registry** - Centralized schema management (in-memory, PostgreSQL, Cloud)
|
|
19
|
+
- 🔁 **Celery Integration** - Full Celery features: retries, time limits, rate limiting, monitoring
|
|
20
|
+
- 📦 **Simple API** - Decorator-based: `@event` and `@subscribe`
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install celery-salt
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Broadcast Example
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from celerysalt import event, subscribe
|
|
34
|
+
|
|
35
|
+
# Define event schema
|
|
36
|
+
@event("user.signup.completed")
|
|
37
|
+
class UserSignupCompleted:
|
|
38
|
+
user_id: int
|
|
39
|
+
email: str
|
|
40
|
+
company_id: int
|
|
41
|
+
signup_source: str = "web"
|
|
42
|
+
|
|
43
|
+
# Publish event
|
|
44
|
+
UserSignupCompleted.publish(
|
|
45
|
+
user_id=123,
|
|
46
|
+
email="alice@example.com",
|
|
47
|
+
company_id=1,
|
|
48
|
+
signup_source="web"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Subscribe to event
|
|
52
|
+
@subscribe("user.signup.completed")
|
|
53
|
+
def send_welcome_email(data: UserSignupCompleted):
|
|
54
|
+
print(f"Sending welcome email to {data.email}")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### RPC Example
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from celerysalt import event, subscribe, RPCError
|
|
61
|
+
|
|
62
|
+
# Define RPC request/response schemas
|
|
63
|
+
@event("rpc.calculator.add", mode="rpc")
|
|
64
|
+
class CalculatorAddRequest:
|
|
65
|
+
a: float
|
|
66
|
+
b: float
|
|
67
|
+
|
|
68
|
+
@event.response("rpc.calculator.add")
|
|
69
|
+
class CalculatorAddResponse:
|
|
70
|
+
result: float
|
|
71
|
+
operation: str = "add"
|
|
72
|
+
|
|
73
|
+
@event.error("rpc.calculator.add")
|
|
74
|
+
class CalculatorAddError:
|
|
75
|
+
error_code: str
|
|
76
|
+
error_message: str
|
|
77
|
+
|
|
78
|
+
# Handler
|
|
79
|
+
@subscribe("rpc.calculator.add")
|
|
80
|
+
def handle_add(data: CalculatorAddRequest) -> CalculatorAddResponse:
|
|
81
|
+
return CalculatorAddResponse(result=data.a + data.b, operation="add")
|
|
82
|
+
|
|
83
|
+
# Client call
|
|
84
|
+
response = CalculatorAddRequest.call(a=10, b=5, timeout=10)
|
|
85
|
+
print(f"Result: {response.result}") # 15.0
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Architecture
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
Publisher → RabbitMQ Exchange (tchu_events) → Subscribers
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- **Exchange**: `tchu_events` (topic exchange, protocol compatible)
|
|
95
|
+
- **Routing**: Topic-based with wildcard support (`user.*`, `#`)
|
|
96
|
+
- **Serialization**: JSON with Pydantic validation
|
|
97
|
+
- **Result Backend**: Redis (required for RPC)
|
|
98
|
+
|
|
99
|
+
## Documentation
|
|
100
|
+
|
|
101
|
+
- [Examples](./examples/) - Working examples for broadcast and RPC
|
|
102
|
+
- [Design Document](./CELERYSALT_DESIGN.md) - Full architecture and design
|
|
103
|
+
- [Implementation Context](./IMPLEMENTATION_CONTEXT.md) - Development context
|
|
104
|
+
|
|
105
|
+
## Requirements
|
|
106
|
+
|
|
107
|
+
- Python 3.10+
|
|
108
|
+
- Celery 5.3+
|
|
109
|
+
- RabbitMQ (message broker)
|
|
110
|
+
- Redis (optional, required for RPC)
|
|
111
|
+
|
|
112
|
+
## Installation
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# Basic installation
|
|
116
|
+
pip install celery-salt
|
|
117
|
+
|
|
118
|
+
# With Django support
|
|
119
|
+
pip install celery-salt[django]
|
|
120
|
+
|
|
121
|
+
# With all extras
|
|
122
|
+
pip install celery-salt[all]
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Examples
|
|
126
|
+
|
|
127
|
+
See the [examples](./examples/) directory for complete working examples:
|
|
128
|
+
|
|
129
|
+
- [Basic Broadcast](./examples/basic_broadcast/) - Pub/sub messaging
|
|
130
|
+
- [Basic RPC](./examples/basic_rpc/) - Request/response pattern
|
|
131
|
+
|
|
132
|
+
Run examples with Docker Compose:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
cd examples
|
|
136
|
+
docker-compose up -d # Starts RabbitMQ and Redis
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Key Concepts
|
|
140
|
+
|
|
141
|
+
### Event Schemas
|
|
142
|
+
|
|
143
|
+
Schemas are defined using Pydantic models and registered at import time:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
@event("user.created")
|
|
147
|
+
class UserCreated:
|
|
148
|
+
user_id: int
|
|
149
|
+
email: str
|
|
150
|
+
created_at: datetime
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Publishing Events
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
# Broadcast (fire-and-forget)
|
|
157
|
+
UserCreated.publish(user_id=123, email="user@example.com", created_at=datetime.now())
|
|
158
|
+
|
|
159
|
+
# RPC (synchronous)
|
|
160
|
+
response = CalculatorAddRequest.call(a=10, b=5, timeout=10)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Subscribing to Events
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
@subscribe("user.created")
|
|
167
|
+
def handle_user_created(data: UserCreated):
|
|
168
|
+
# Process event
|
|
169
|
+
pass
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### RPC Response Validation
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
@event.response("rpc.calculator.add")
|
|
176
|
+
class CalculatorAddResponse:
|
|
177
|
+
result: float
|
|
178
|
+
|
|
179
|
+
@event.error("rpc.calculator.add")
|
|
180
|
+
class CalculatorAddError:
|
|
181
|
+
error_code: str
|
|
182
|
+
error_message: str
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Protocol Compatibility
|
|
186
|
+
|
|
187
|
+
CelerySalt maintains protocol compatibility with `tchu-tchu`:
|
|
188
|
+
- Same exchange name: `tchu_events`
|
|
189
|
+
- Same message format: `_tchu_meta` field
|
|
190
|
+
- Same routing key conventions
|
|
191
|
+
|
|
192
|
+
This allows gradual migration: apps using `celery-salt` can communicate with apps still using `tchu-tchu`.
|
|
193
|
+
|
|
194
|
+
## Development
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Clone repository
|
|
198
|
+
git clone https://github.com/sigularusrex/celery-salt.git
|
|
199
|
+
cd celery-salt
|
|
200
|
+
|
|
201
|
+
# Install development dependencies
|
|
202
|
+
pip install -e ".[dev]"
|
|
203
|
+
|
|
204
|
+
# Run tests
|
|
205
|
+
pytest
|
|
206
|
+
|
|
207
|
+
# Run examples
|
|
208
|
+
cd examples
|
|
209
|
+
docker-compose up -d
|
|
210
|
+
celery -A basic_broadcast.subscriber worker --loglevel=info
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
MIT License - see [LICENSE](./LICENSE) file for details.
|
|
216
|
+
|
|
217
|
+
## Contributing
|
|
218
|
+
|
|
219
|
+
Contributions welcome! Please open an issue or pull request on GitHub.
|
|
220
|
+
|
|
221
|
+
## Links
|
|
222
|
+
|
|
223
|
+
- **GitHub**: https://github.com/sigularusrex/celery-salt
|
|
224
|
+
- **Documentation**: https://github.com/sigularusrex/celery-salt
|
|
225
|
+
- **Issues**: https://github.com/sigularusrex/celery-salt/issues
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CelerySalt: Event-driven architecture library for Python.
|
|
3
|
+
|
|
4
|
+
Extends Celery with event publishing/subscribing patterns, schema validation,
|
|
5
|
+
and automatic retries while maintaining the familiar Celery developer experience.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from celery_salt.core import event, subscribe, RPCError
|
|
9
|
+
from celery_salt.integrations.dispatcher import (
|
|
10
|
+
create_topic_dispatcher,
|
|
11
|
+
get_subscribed_routing_keys,
|
|
12
|
+
)
|
|
13
|
+
from celery_salt.version import __version__
|
|
14
|
+
|
|
15
|
+
# Protocol compatibility: Keep exchange name for backward compatibility
|
|
16
|
+
DEFAULT_EXCHANGE_NAME = "tchu_events"
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"event",
|
|
20
|
+
"subscribe",
|
|
21
|
+
"RPCError",
|
|
22
|
+
"create_topic_dispatcher",
|
|
23
|
+
"get_subscribed_routing_keys",
|
|
24
|
+
"DEFAULT_EXCHANGE_NAME",
|
|
25
|
+
"__version__",
|
|
26
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Core CelerySalt functionality."""
|
|
2
|
+
|
|
3
|
+
from celery_salt.core.decorators import event, subscribe
|
|
4
|
+
from celery_salt.core.exceptions import (
|
|
5
|
+
CelerySaltError,
|
|
6
|
+
SchemaConflictError,
|
|
7
|
+
SchemaRegistryUnavailableError,
|
|
8
|
+
RPCError,
|
|
9
|
+
PublishError,
|
|
10
|
+
TimeoutError,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
# Expose response and error decorators via event function
|
|
14
|
+
# Usage: @event.response("rpc.topic") or @event.error("rpc.topic")
|
|
15
|
+
from celery_salt.core.decorators import response, error
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"event",
|
|
19
|
+
"subscribe",
|
|
20
|
+
"CelerySaltError",
|
|
21
|
+
"SchemaConflictError",
|
|
22
|
+
"SchemaRegistryUnavailableError",
|
|
23
|
+
"RPCError",
|
|
24
|
+
"PublishError",
|
|
25
|
+
"TimeoutError",
|
|
26
|
+
]
|