A universal inter-service communication protocol based on ATTP-core which was firstly designed for tool calling.
Project description
ATTP Software Development Kit
The robust Python SDK for building distributed services with the ATTP protocol.
📖 Introduction
attp-sdk is the official Python library for integrating with the Ascender ecosystem using the ATTP (Ascender Tool Transmission Protocol). It provides a powerful set of tools to build high-performance, scalable, and reactive microservices.
With attp-sdk, you can effortlessly create controllers, handle RPC calls, manage events, and orchestrate service lifecycles, all while leveraging the robustness of the Ascender Framework.
⚡ Features
- RPC Decoration: Simple
@AttpCalldecorators to expose methods as RPC endpoints. - Event Driven: Reactive
@AttpEventhandlers for asynchronous communication. - Lifecycle Management: Hooks for
@AttpLifecycleevents likeconnectanddisconnect. - Error Handling: Centralized
@AttpErrorHandlerfor graceful failure management. - Dependency Injection: Seamless integration with Ascender's DI system.
- Transmitter: Fluent API for sending requests and notifications.
📦 Installation
Install via Poetry:
poetry add attp-sdk
Or using Pip:
pip install attp-sdk
Or using UV:
uv add attp-sdk
⚙️ Configuration
attp-sdk uses a configuration file (usually attp.jsonc or attp.json) to define node identity, authentication, and peer services.
Example attp.jsonc
{
"node": {
"name": "my-service",
"bind": "0.0.0.0:6563"
},
"caps": ["schema/msgpack", "streaming"],
"client": {
"auth": {
"mode": "hmac",
"secret": { "env": "ATTP_SHARED_SECRET" },
"node_id": "my-service",
"ttl_seconds": 30
}
},
"services": {
"peers": [
{ "namespace": "core-service", "uri": "attp://core-api:6563" }
]
}
}
🚀 Usage
Creating a Controller
Define your service logic using a class-based controller.
from ascender.core import Controller
from attp.decorators import AttpCall, AttpEvent, AttpLifecycle
from attp.types.frame import AttpFrameDTO
class EchoRequest(AttpFrameDTO):
message: str
class EchoResponse(AttpFrameDTO):
message: str
@Controller(
standalone=True,
providers=[],
)
class MyController:
@AttpCall("echo", namespace="core-service")
async def echo(self, payload: EchoRequest) -> EchoResponse:
print(f"Received: {payload.message}")
return EchoResponse(message=payload.message)
@AttpEvent("user.created")
async def on_user_created(self, payload: dict):
print(f"New user: {payload.get('id')}")
@AttpLifecycle("connect")
async def on_connect(self, meta: dict):
print("Connected to ATTP network")
Sending Messages
Use the AttpTransmitter to send requests or emit events.
from attp.shared.transmitter import AttpTransmitter
# In your controller or service
async def trigger_action(self):
response = await self.transmitter.send(
"remote_procedure",
MyPayload(data="foo"),
namespace="target-service",
expected_response=MyResponse
)
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file attp_sdk-0.1.2.tar.gz.
File metadata
- Download URL: attp_sdk-0.1.2.tar.gz
- Upload date:
- Size: 32.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.13 Linux/6.18.2-arch2-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5b1da4159ff66768feaf54070f3678c3f3b01f031a62f37a4c5aec3b38e861a
|
|
| MD5 |
9fc5c9c14f39a2a3d7a3262564503d69
|
|
| BLAKE2b-256 |
ed26b5b1d5aec0e128b5e2f04e72a5d51731e9456d63a36899bbff6bf6bdc578
|
File details
Details for the file attp_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: attp_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 50.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.13 Linux/6.18.2-arch2-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a4af6bfa7e8a7a0b20383b0fe7eb9ec0ce560410fd9d2b09f67fe77a83b1fa6
|
|
| MD5 |
e6315cfb6f0c836b7c14aa0d092c87df
|
|
| BLAKE2b-256 |
5277b917aafd8d2a1b1dd723dbeb4d3a8e86ebbe9fda9f965ef91677a6a7cf93
|