Skip to main content

larzws

WebSockets in pure Python. Zero dependencies.

A real RFC 6455 WebSocket server and client with nothing to install — no websockets, no aiohttp, no async runtime. Handshake, framing, masking, fragmentation, ping/pong, and close are handled; you just send and receive.

from larzws import serve, connect

# server — echo
def handler(ws):
    for message in ws:                 # iterate messages until the client leaves
        ws.send("echo: " + message)
serve(handler, "127.0.0.1", 8765)

# client
ws = connect("ws://127.0.0.1:8765")
ws.send("hello")
print(ws.recv())                       # "echo: hello"
ws.close()

What makes it different

  • No async, no dependency. Most WebSocket libraries drag in an async stack. larzws is plain sockets + threads — drop it into any script or service.
  • Server and client, both real. Full RFC 6455: the Upgrade handshake, binary framing with 7/16/64-bit lengths, client-side masking, fragmentation reassembly, automatic ping→pong, and clean close.
  • Text and binary. str messages go as text frames, bytes as binary; you get back the right type.
  • Easy to embed. Threaded server (one thread per connection) with start_background() for tests and apps.

Pairs naturally with larzrpc for realtime request/response over a socket.

Install

pip install larzws

Server

from larzws import WebSocketServer, serve

def handler(ws):
    ws.send("welcome")
    for message in ws:
        ws.send("you said: " + message)

serve(handler, "0.0.0.0", 8765)          # blocking

# or embed it
server = WebSocketServer("127.0.0.1", 8765, handler)
server.start_background()                # daemon thread; server.port is resolved
...
server.shutdown()

Client

from larzws import connect

ws = connect("ws://127.0.0.1:8765/chat")
ws.send("hi")               # text
ws.send(b"\x00\x01")        # binary
msg = ws.recv()             # str or bytes, or None when closed
for msg in ws:              # or iterate until close
    ...
ws.ping()
ws.close()

Scope

larzws speaks plain ws:// (not wss:///TLS in this version — terminate TLS at a reverse proxy if you need it) and uses a thread per connection, which is ideal for tools, internal services, dashboards, and realtime features up to moderate concurrency. For tens of thousands of idle connections you'd want an async library; for everything else, this is refreshingly simple.

Tests

python -m unittest discover -s tests -v   # 14 tests: RFC handshake, framing, e2e echo

The Larz stack

Pure-Python, zero-dependency building blocks: larz · larzchain · larzmoney · larzcrypt · larzdb · larzagent · larzchart · larzmark · larztask · larzvault · larzvm · larzcache · larzvalidate · larzid · larzrpc · larzstate · larzhttp · larzconf · larzcron · larzlimit · larzlog · larzcli · larzretry · larztime · larzpdf · larzpack · larztemplate · larzcolor · larztable · larzjson · larzbus · larzmigrate · larzgraph · larzws

License

MIT © larz-scripter

Metadata

Release files for larzws 0.1.0

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

Source distribution (sdist)

Source distribution for larzws 0.1.0
File Size Uploaded Provenance
larzws-0.1.0.tar.gz 9.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 18.0 kB

Release files / larzws-0.1.0.tar.gz

Download URL larzws-0.1.0.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7d702b4e00413fea64a83d1411b919a4657da9c79b7c6ad0e422045267a8bf5b
BLAKE2b-256 checksum
How to use checksums
df1a5bd3d73a1caa65a3c7c26aa6bb02f1723eeaee4728b8f6b4810ab4e511ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / larzws-0.1.0-py3-none-any.whl

Download URL larzws-0.1.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2faca701e6ea3b046f00460909e475622fbb4ba64032f42447b3441fcc7df58
BLAKE2b-256 checksum
How to use checksums
fde07ff1c921b073aa8a19b34cd5dc7c9674ad128fe4eac555633d9f7c4f7e26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for larzws 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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