neonlink-client 1.3.15__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.
- neonlink_client-1.3.15/.gitignore +82 -0
- neonlink_client-1.3.15/CHANGELOG.md +71 -0
- neonlink_client-1.3.15/LICENSE +21 -0
- neonlink_client-1.3.15/PKG-INFO +285 -0
- neonlink_client-1.3.15/PY3_DEV_DEBT.md +1313 -0
- neonlink_client-1.3.15/README.md +248 -0
- neonlink_client-1.3.15/examples/finai_integration.py +163 -0
- neonlink_client-1.3.15/examples/middleware_example.py +95 -0
- neonlink_client-1.3.15/examples/publish.py +41 -0
- neonlink_client-1.3.15/examples/retry_example.py +56 -0
- neonlink_client-1.3.15/examples/subscribe.py +62 -0
- neonlink_client-1.3.15/pyproject.toml +75 -0
- neonlink_client-1.3.15/tests/__init__.py +1 -0
- neonlink_client-1.3.15/tests/conftest.py +28 -0
- neonlink_client-1.3.15/tests/test_client.py +536 -0
- neonlink_client-1.3.15/tests/test_config.py +203 -0
- neonlink_client-1.3.15/tests/test_helpers.py +113 -0
- neonlink_client-1.3.15/tests/test_middleware.py +224 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Binaries for programs and plugins
|
|
2
|
+
*.exe
|
|
3
|
+
*.exe~
|
|
4
|
+
*.dll
|
|
5
|
+
*.so
|
|
6
|
+
*.dylib
|
|
7
|
+
|
|
8
|
+
# Test binary, built with `go test -c`
|
|
9
|
+
*.test
|
|
10
|
+
|
|
11
|
+
# Output of the go coverage tool
|
|
12
|
+
*.out
|
|
13
|
+
|
|
14
|
+
# Dependency directories
|
|
15
|
+
vendor/
|
|
16
|
+
|
|
17
|
+
# Go workspace file
|
|
18
|
+
go.work
|
|
19
|
+
|
|
20
|
+
# Environment variables
|
|
21
|
+
# .env
|
|
22
|
+
.env.local
|
|
23
|
+
.env.*.local
|
|
24
|
+
.env.staging
|
|
25
|
+
.env.production
|
|
26
|
+
*.env
|
|
27
|
+
!.env.example
|
|
28
|
+
|
|
29
|
+
# IDE specific files
|
|
30
|
+
.idea/
|
|
31
|
+
.vscode/
|
|
32
|
+
*.swp
|
|
33
|
+
*.swo
|
|
34
|
+
|
|
35
|
+
*~
|
|
36
|
+
|
|
37
|
+
# OS generated files
|
|
38
|
+
.DS_Store
|
|
39
|
+
.DS_Store?
|
|
40
|
+
._*
|
|
41
|
+
.Spotlight-V100
|
|
42
|
+
.Trashes
|
|
43
|
+
ehthumbs.db
|
|
44
|
+
Thumbs.db
|
|
45
|
+
|
|
46
|
+
# Application specific
|
|
47
|
+
logs/
|
|
48
|
+
tmp/
|
|
49
|
+
dist/
|
|
50
|
+
build/
|
|
51
|
+
|
|
52
|
+
# Certificates
|
|
53
|
+
*.pem
|
|
54
|
+
*.key
|
|
55
|
+
*.crt
|
|
56
|
+
|
|
57
|
+
# Database files
|
|
58
|
+
*.db
|
|
59
|
+
*.sqlite
|
|
60
|
+
|
|
61
|
+
# Temporary files
|
|
62
|
+
*.tmp
|
|
63
|
+
*.bak
|
|
64
|
+
*.backup/neonlink
|
|
65
|
+
|
|
66
|
+
# Build artifacts (Go binaries in root)
|
|
67
|
+
/neonlink
|
|
68
|
+
/debug-client
|
|
69
|
+
|
|
70
|
+
# Temp files
|
|
71
|
+
tmp/
|
|
72
|
+
bin/
|
|
73
|
+
|
|
74
|
+
# JWT tokens directory (sensitive)
|
|
75
|
+
tokens/
|
|
76
|
+
*.token
|
|
77
|
+
|
|
78
|
+
# Ignore stray archived draft file
|
|
79
|
+
documents/10-archive/archive/insight_service_input copy.md
|
|
80
|
+
|
|
81
|
+
# Ignore stray archived draft file
|
|
82
|
+
documents/10-archive/archive/insight_service_input copy.md
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the NeonLink Python SDK will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Nothing yet
|
|
12
|
+
|
|
13
|
+
## [1.0.0] - 2025-12-06
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- Initial release of NeonLink Python SDK
|
|
17
|
+
- **Core Client** (`NeonLinkClient`)
|
|
18
|
+
- Async/await support with `grpcio`
|
|
19
|
+
- Context manager support (`async with`)
|
|
20
|
+
- Connection management with auto-reconnection
|
|
21
|
+
- TLS/mTLS support for secure connections
|
|
22
|
+
- **Configuration** (`ConfigBuilder`, `NeonLinkConfig`)
|
|
23
|
+
- Builder pattern for fluent configuration
|
|
24
|
+
- Environment variable support (`NEONLINK_*`)
|
|
25
|
+
- TLS configuration (`TLSConfig`)
|
|
26
|
+
- Retry policy configuration (`RetryPolicy`)
|
|
27
|
+
- **Middleware System**
|
|
28
|
+
- `LoggingMiddleware` - Request/response logging
|
|
29
|
+
- `RetryMiddleware` - Exponential backoff retries
|
|
30
|
+
- `TimeoutMiddleware` - Request timeout enforcement
|
|
31
|
+
- `RecoveryMiddleware` - Exception handling
|
|
32
|
+
- `MetricsMiddleware` - Performance metrics collection
|
|
33
|
+
- **Message Building** (`MessageBuilder`)
|
|
34
|
+
- Fluent builder pattern for message construction
|
|
35
|
+
- Automatic UUID generation for message IDs
|
|
36
|
+
- JSON payload support
|
|
37
|
+
- Idempotency key support (explicit and field-based generation)
|
|
38
|
+
- **Helper Functions**
|
|
39
|
+
- `get_identity_context()` - Extract identity headers
|
|
40
|
+
- `get_webhook_ingress_context()` - Extract webhook headers
|
|
41
|
+
- `get_active_job_type_name()` - Get job type from headers
|
|
42
|
+
- `get_job_type_message()` - Get job type message from headers
|
|
43
|
+
- **Error Handling**
|
|
44
|
+
- `NeonLinkError` - Base exception class
|
|
45
|
+
- `ConnectionError` - Connection failures
|
|
46
|
+
- `TimeoutError` - Request timeouts
|
|
47
|
+
- `PublishError` - Publish failures
|
|
48
|
+
- `SubscribeError` - Subscription failures
|
|
49
|
+
- `AckError` - Acknowledgment failures
|
|
50
|
+
- `ConfigurationError` - Invalid configuration
|
|
51
|
+
- **gRPC Operations**
|
|
52
|
+
- `publish()` - Send messages to streams
|
|
53
|
+
- `subscribe()` - Stream messages with async iterator
|
|
54
|
+
- `ack()` - Acknowledge processed messages
|
|
55
|
+
- `nack()` - Negative acknowledge failed messages
|
|
56
|
+
- `get_stream_health()` - Check stream health metrics
|
|
57
|
+
- `health_check()` - Connection health verification
|
|
58
|
+
|
|
59
|
+
### Feature Parity
|
|
60
|
+
- Full feature parity with Go SDK v1.0.8
|
|
61
|
+
- All core operations supported
|
|
62
|
+
- Middleware chain compatible with Go SDK patterns
|
|
63
|
+
- Idempotency key generation matches Go SDK algorithm
|
|
64
|
+
|
|
65
|
+
### Documentation
|
|
66
|
+
- Comprehensive README with quick start guide
|
|
67
|
+
- Five example scripts demonstrating usage patterns
|
|
68
|
+
- Type hints throughout for IDE support
|
|
69
|
+
|
|
70
|
+
[Unreleased]: https://github.com/LetA-Tech/mcfo-neonlink/compare/py3-v1.0.0...HEAD
|
|
71
|
+
[1.0.0]: https://github.com/LetA-Tech/mcfo-neonlink/releases/tag/py3-v1.0.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 LetA Tech
|
|
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,285 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: neonlink-client
|
|
3
|
+
Version: 1.3.15
|
|
4
|
+
Summary: Official Python client for NeonLink message broker
|
|
5
|
+
Project-URL: Homepage, https://github.com/LetA-Tech/mcfo-neonlink
|
|
6
|
+
Project-URL: Documentation, https://github.com/LetA-Tech/mcfo-neonlink/tree/main/py3
|
|
7
|
+
Project-URL: Repository, https://github.com/LetA-Tech/mcfo-neonlink.git
|
|
8
|
+
Project-URL: Changelog, https://github.com/LetA-Tech/mcfo-neonlink/blob/main/py3/CHANGELOG.md
|
|
9
|
+
Author-email: LetA Tech <dev@leta.tech>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: async,grpc,mellions,message-broker,neonlink,redis-streams
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Framework :: AsyncIO
|
|
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.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: grpcio-tools>=1.60.0
|
|
26
|
+
Requires-Dist: grpcio>=1.60.0
|
|
27
|
+
Requires-Dist: neoncontract-gen>=1.3.15
|
|
28
|
+
Requires-Dist: protobuf>=4.25.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: grpcio-testing>=1.60.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: mypy>=1.8.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# NeonLink Python SDK
|
|
39
|
+
|
|
40
|
+
Official Python client library for NeonLink message broker. Full feature parity with the Go SDK.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install neonlink-client
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or install from source:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
cd py3
|
|
52
|
+
pip install -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For development:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install -e ".[dev]"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Requirements
|
|
62
|
+
|
|
63
|
+
- Python >= 3.10
|
|
64
|
+
- gRPC runtime (`grpcio`)
|
|
65
|
+
- Protocol Buffers (`protobuf`)
|
|
66
|
+
|
|
67
|
+
## Quick Start
|
|
68
|
+
|
|
69
|
+
### Publishing Messages
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import asyncio
|
|
73
|
+
from neonlink import NeonLinkClient, ConfigBuilder, MessageBuilder
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
async def main():
|
|
77
|
+
config = (
|
|
78
|
+
ConfigBuilder()
|
|
79
|
+
.with_service_name("my-service")
|
|
80
|
+
.with_address("neonlink:9090")
|
|
81
|
+
.build()
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
async with NeonLinkClient(config) as client:
|
|
85
|
+
request = (
|
|
86
|
+
MessageBuilder()
|
|
87
|
+
.with_stream("my-stream")
|
|
88
|
+
.with_message_type("MyMessage")
|
|
89
|
+
.with_json_payload({"key": "value"})
|
|
90
|
+
.with_idempotency_fields("user-123", "action-456")
|
|
91
|
+
.build()
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
response = await client.publish(request)
|
|
95
|
+
print(f"Published: {response.message_id}")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
asyncio.run(main())
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Subscribing to Streams
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import asyncio
|
|
105
|
+
from neonlink import NeonLinkClient, ConfigBuilder
|
|
106
|
+
from neoncontract.messaging.v1 import messaging_pb2
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
async def main():
|
|
110
|
+
config = (
|
|
111
|
+
ConfigBuilder()
|
|
112
|
+
.with_service_name("my-worker")
|
|
113
|
+
.with_address("neonlink:9090")
|
|
114
|
+
.build()
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
async with NeonLinkClient(config) as client:
|
|
118
|
+
client.enable_auto_reconnect()
|
|
119
|
+
|
|
120
|
+
request = messaging_pb2.SubscribeRequest(
|
|
121
|
+
stream="my-stream",
|
|
122
|
+
consumer_group="my-workers",
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
async for message in client.subscribe(request):
|
|
126
|
+
print(f"Received: {message.message_id}")
|
|
127
|
+
|
|
128
|
+
# Process message...
|
|
129
|
+
|
|
130
|
+
await client.ack(messaging_pb2.AckRequest(
|
|
131
|
+
message_id=message.message_id,
|
|
132
|
+
stream=message.stream,
|
|
133
|
+
))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
asyncio.run(main())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Configuration
|
|
140
|
+
|
|
141
|
+
### From Code
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from neonlink import ConfigBuilder
|
|
145
|
+
|
|
146
|
+
config = (
|
|
147
|
+
ConfigBuilder()
|
|
148
|
+
.with_service_name("my-service")
|
|
149
|
+
.with_address("neonlink:9090")
|
|
150
|
+
.with_timeout(30.0)
|
|
151
|
+
.with_retry_policy(max_retries=3, initial_backoff=0.1)
|
|
152
|
+
.with_tls(
|
|
153
|
+
cert_path="/path/to/cert.pem",
|
|
154
|
+
key_path="/path/to/key.pem",
|
|
155
|
+
ca_path="/path/to/ca.pem",
|
|
156
|
+
)
|
|
157
|
+
.build()
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### From Environment Variables
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from neonlink import NeonLinkConfig
|
|
165
|
+
|
|
166
|
+
config = NeonLinkConfig.from_env()
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Environment variables:
|
|
170
|
+
- `NEONLINK_SERVICE_NAME` (required)
|
|
171
|
+
- `NEONLINK_ADDRESS` (default: `localhost:9090`)
|
|
172
|
+
- `NEONLINK_TIMEOUT` (default: `30`)
|
|
173
|
+
- `NEONLINK_TLS_CERT`
|
|
174
|
+
- `NEONLINK_TLS_KEY`
|
|
175
|
+
- `NEONLINK_TLS_CA`
|
|
176
|
+
- `NEONLINK_TLS_INSECURE`
|
|
177
|
+
|
|
178
|
+
## Middleware
|
|
179
|
+
|
|
180
|
+
Add middleware for logging, retries, timeouts, and metrics:
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
from neonlink import (
|
|
184
|
+
NeonLinkClient,
|
|
185
|
+
LoggingMiddleware,
|
|
186
|
+
RetryMiddleware,
|
|
187
|
+
TimeoutMiddleware,
|
|
188
|
+
MetricsMiddleware,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
middlewares = [
|
|
192
|
+
LoggingMiddleware(),
|
|
193
|
+
RetryMiddleware(max_retries=3),
|
|
194
|
+
TimeoutMiddleware(timeout=10.0),
|
|
195
|
+
MetricsMiddleware(my_metrics_collector),
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
client = NeonLinkClient(config, middlewares=middlewares)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Idempotency
|
|
202
|
+
|
|
203
|
+
Use the `MessageBuilder` to ensure idempotent message delivery:
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
from neonlink import MessageBuilder
|
|
207
|
+
|
|
208
|
+
# Option 1: Explicit idempotency key
|
|
209
|
+
request = (
|
|
210
|
+
MessageBuilder()
|
|
211
|
+
.with_stream("my-stream")
|
|
212
|
+
.with_message_type("MyMessage")
|
|
213
|
+
.with_idempotency_key("unique-key-123")
|
|
214
|
+
.build()
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
# Option 2: Generate from fields (recommended)
|
|
218
|
+
request = (
|
|
219
|
+
MessageBuilder()
|
|
220
|
+
.with_stream("my-stream")
|
|
221
|
+
.with_message_type("MyMessage")
|
|
222
|
+
.with_idempotency_fields("user-123", "action-456", "timestamp")
|
|
223
|
+
.build()
|
|
224
|
+
)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Proto Definitions
|
|
228
|
+
|
|
229
|
+
The SDK uses protobuf definitions from the `neoncontract` package, which is automatically
|
|
230
|
+
installed as a dependency. The package provides all message types for the NeonLink gRPC service.
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
# Import protobuf types directly from neoncontract
|
|
234
|
+
from neoncontract.messaging.v1 import messaging_pb2
|
|
235
|
+
|
|
236
|
+
# Available types:
|
|
237
|
+
# - messaging_pb2.PublishRequest
|
|
238
|
+
# - messaging_pb2.PublishResponse
|
|
239
|
+
# - messaging_pb2.SubscribeRequest
|
|
240
|
+
# - messaging_pb2.StreamMessage
|
|
241
|
+
# - messaging_pb2.AckRequest
|
|
242
|
+
# - messaging_pb2.AckResponse
|
|
243
|
+
# - messaging_pb2.NackRequest
|
|
244
|
+
# - messaging_pb2.NackResponse
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Development
|
|
248
|
+
|
|
249
|
+
### Running Tests
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
pytest
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
With coverage:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
pytest --cov=neonlink --cov-report=html
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Type Checking
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
mypy neonlink
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Linting
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
ruff check neonlink
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Examples
|
|
274
|
+
|
|
275
|
+
See the `examples/` directory for complete examples:
|
|
276
|
+
|
|
277
|
+
- `publish.py` - Basic publishing
|
|
278
|
+
- `subscribe.py` - Subscribing and processing
|
|
279
|
+
- `middleware_example.py` - Using middleware
|
|
280
|
+
- `finai_integration.py` - FinAI service integration
|
|
281
|
+
- `retry_example.py` - Retry behavior
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
MIT License - see LICENSE file.
|