The Python Telepact library
Project description
Telepact
Installation
pip install telepact
Usage
API:
[
{
"fn.greet": {
"subject": "string"
},
"->": {
"Ok_": {
"message": "string"
}
}
}
]
Server:
files = TelepactSchemaFiles('/directory/containing/api/files')
schema = TelepactSchema.from_file_json_map(files.filenames_to_json)
async def handler(request_message: 'Message') -> 'Message':
function_name = request_message.body.keys[0]
arguments = request_message.body[function_name]
try:
# Early in the handler, perform any pre-flight "middleware" operations, such as
# authentication, tracing, or logging.
log.info("Function started", {'function': function_name})
# Dispatch request to appropriate function handling code.
# (This example uses manual dispatching, but you can also use a more advanced pattern.)
if function_name == 'fn.greet':
subject = arguments['subject']
return Message({}, {'Ok_': {'message': f'Hello {subject}!'}})
raise Exception('Function not found')
finally:
# At the end the handler, perform any post-flight "middleware" operations
log.info("Function finished", {'function': function_name})
options = Server.Options()
server = Server(schema, handler, options)
# Wire up request/response bytes from your transport of choice
async def transport_handler(request_bytes: bytes) -> bytes:
response_bytes = await server.process(request_bytes)
return response_bytes
transport.receive(transport_handler)
Client:
async def adapter(m: Message, s: Serializer) -> Message:
request_bytes = s.serialize(m)
# Wire up request/response bytes to your transport of choice
response_bytes = await transport.send(request_bytes)
return s.deserialize(response_bytes)
options = Client.Options()
client = Client(adapter, options)
For more concrete usage examples, see the tests.
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
telepact-1.0.0a150.tar.gz
(45.7 kB
view details)
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
telepact-1.0.0a150-py3-none-any.whl
(153.4 kB
view details)
File details
Details for the file telepact-1.0.0a150.tar.gz.
File metadata
- Download URL: telepact-1.0.0a150.tar.gz
- Upload date:
- Size: 45.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b04701dc487f5550efe7bab58828fc10f37509efe5ee80af028208dea25b3883
|
|
| MD5 |
290948aa5293bc5a7af8c8f646e847ef
|
|
| BLAKE2b-256 |
bae7b34117fae5fbf238319533ab37f352c73c99df6ba81c72d4d42ac6794555
|
File details
Details for the file telepact-1.0.0a150-py3-none-any.whl.
File metadata
- Download URL: telepact-1.0.0a150-py3-none-any.whl
- Upload date:
- Size: 153.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0a4fe79b7d5a0f97b9de881b2d53a315a0af728619748125fa782dd59d1e8dd
|
|
| MD5 |
f2fc5782a0e977390112f90d37877809
|
|
| BLAKE2b-256 |
1de6ea4ada773f2171e4c86870655d03fe9a5ba5f67cf43d5f8b81077ea9fd6b
|