Skip to main content

Simple asyncio TCP client and server library inspired by fastapi

Project description

netaio

This is designed to be a simple and easy to use asyncio-based TCP client and server implementation inspired by fastapi but for non-HTTP use cases.

Status

This is currently a work-in-progress. Remaining work before the v0.1.0 release:

  • Add authorization plugin
  • Add encryption plugin
  • Add optional authorization plugin using tapescript
  • Add optional encryption plugin using simple symmetric stream cipher
  • More thorough test suite
  • Better usage examples/documentation

After that, issues will be tracked here.

Usage

For more documentation, see the dox.md file generated by autodox.

Server

from netaio import TCPServer, Body, Message, MessageType
import asyncio


server = TCPServer("0.0.0.0", 8888)

@server.on((MessageType.REQUEST_URI, b'something'))
async def something(msg: Message):
    body = Body.prepare(b'This is it.', uri=b'something')
    return Message.prepare(body, MessageType.RESPOND_URI)

asyncio.run(server.start())

Client

from netaio import TCPClient, Body, Message, MessageType
import asyncio


client = TCPClient("127.0.0.1", 8888)
received_resources = {}

@client.on(MessageType.RESPOND_URI)
def echo(msg: Message):
    received_resources[msg.body.uri] = msg.body.content

async def run_client():
    request_body = Body.prepare(b'pls gibs me dat', uri=b'something')
    request_message = Message.prepare(request_body, MessageType.REQUEST_URI)
    await client.connect()
    await client.send(request_message)
    await client.receive_once()

asyncio.run(run_client())

print(received_resources)

License

Copyright (c) 2025 Jonathan Voss (k98kurz)

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyleft notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netaio-0.0.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

netaio-0.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file netaio-0.0.1.tar.gz.

File metadata

  • Download URL: netaio-0.0.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for netaio-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bdfe48f49b31d7b769192ff20b44c27588ad3be9c5f6cac785565d3727744893
MD5 629a366fd29f6513f8a9ac240eef71fe
BLAKE2b-256 ebeb2bcc86ead2dd8dec20999028f0ebae02cb3cd93f1a2d339930b59266030c

See more details on using hashes here.

File details

Details for the file netaio-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: netaio-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for netaio-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ec0386320da89ebf6322abcceb45877ce9811de7f5fc1cf97a697ed3931be6e
MD5 346e966c31a9507d3b362684108c464b
BLAKE2b-256 73efa3bcc1105fe9d5c9c84ed340ffbbf2617ba68972c27f20f9ffdb12fb4acb

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