Skip to main content

Server Usage

import aiochat
import aiohttp.web

class Agent(aiochat.ServerAgent):

    @aiochat.use
    async def join(self, *args, delimit = ','):

        return delimit.join(map(str, args))

app = aiohttp.web.Application()

routes = aiohttp.web.RouteTableDef()

@routes.get('/connect')
async def handle(request):

    websocket = aiohttp.web.WebSocketResponse()

    await websocket.prepare(request)

    agent = Agent()

    await agent.start(websocket)

    value = 'eggs and bacon and salad'

    # remote call
    result = await agent.split(value, delimit = ' and ')

    print('result:', result)

    # wait until disconnection
    await agent.wait()

    return websocket

app.router.add_routes(routes)

aiohttp.web.run_app(app)

Client Usage

import aiochat
import aiohttp
import asyncio

class Agent(aiochat.ClientAgent):

    @aiochat.use
    async def split(self, value, delimit = ','):

        return value.split(delimit)

loop = asyncio.get_event_loop()

url = 'http://localhost:8080/connect'

async def main():

    session = aiohttp.ClientSession(loop = loop)

    async def connect():

        while not session.closed:

            try:

                websocket = await session.ws_connect(url)

            except aiohttp.ClientError:

                await asyncio.sleep(0.5)

            else:

                break

        return websocket

    agent = Agent(connect)

    await agent.start()

    values = ('crooked man', 'mile', 'sixpence', 'stile')

    # remote call
    result = await agent.join(*values, delimit = ' ')

    print('result:', result)

    # disconnect
    await agent.stop()

    await session.close()

coroutine = main()

loop.run_until_complete(coroutine)

Details

  • Clients will attempt to auto-reconnect until told to stop.
  • Method names have to follow python function name limitations.
  • The reconnection protocol reserves the hello alert methods.
  • Implementation reserves the bind wait start stop methods.
  • Annotations are not considered; schema checking should be done manually.
  • Keyword arguments cannot be passed in a positional manner and vice versa.
  • WebSockets should not be used outside of Agent context while connected.

Installing

python3 -m pip install aiochat

Metadata

Release files for aiochat 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiochat 0.0.3
File Size Uploaded
aiochat-0.0.3.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiochat 0.0.3
File Interpreter ABI Platform
aiochat-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / aiochat-0.0.3.tar.gz

Download URL aiochat-0.0.3.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
57af3dfc03caeadae565106265dfc3c872b75e84e80798ea10f79ca6a974a290
BLAKE2b-256 checksum
How to use checksums
7fc4cb9cedaf8af0b70f4f636068b0d9e61a4ec3eee3766e12ff0d31575d9174
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.8.1

Release files / aiochat-0.0.3-py3-none-any.whl

Download URL aiochat-0.0.3-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a93ba0fd31a2bb20892f3bc128351029b6543eb1713cac7efb0e29a1c86cf556
BLAKE2b-256 checksum
How to use checksums
2eae9da7b5be51974bc51cf0d7174b942fd991d5e35fa8e91c1f50a24668f0bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page