Skip to main content

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]

    if function_name == 'fn.greet':
        subject = arguments['subject']
        return Message({}, {'Ok_': {'message': f'Hello {subject}!'}})

    raise Exception('Function not found')

options = Server.Options()
server = Server(schema, handler, options)

# Wire up request/response bytes from your transport of choice
response_bytes = server.process(request_bytes)

Client:

async def adapter(m: Message, s: Serializer) -> Message:
    request_bytes = s.serialize(m)

    # Wire up request/response bytes to your transport of choice

    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.0a129.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telepact-1.0.0a129-py3-none-any.whl (151.7 kB view details)

Uploaded Python 3

File details

Details for the file telepact-1.0.0a129.tar.gz.

File metadata

  • Download URL: telepact-1.0.0a129.tar.gz
  • Upload date:
  • Size: 44.5 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

Hashes for telepact-1.0.0a129.tar.gz
Algorithm Hash digest
SHA256 aed972928d47eefbba477279a926e12945aac986fea3db0cb4c7bc1618c46a9f
MD5 35566c46e6cfbd9c8d098bb524108d0f
BLAKE2b-256 ea7d2ee467f2baa96cd725fb3d024232187c5ea95546c41db488c6b6b5c462f2

See more details on using hashes here.

File details

Details for the file telepact-1.0.0a129-py3-none-any.whl.

File metadata

  • Download URL: telepact-1.0.0a129-py3-none-any.whl
  • Upload date:
  • Size: 151.7 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

Hashes for telepact-1.0.0a129-py3-none-any.whl
Algorithm Hash digest
SHA256 03a519433d242be2b032461deb081cdeeea371d2328ab544cdd99e3a4a0cfe3b
MD5 c93b79eedc520b3d87170018bf6e34cb
BLAKE2b-256 6bc8f991f57389e95e907777b985fa204effe8b352ea92c0e430da43a84e541c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page