Skip to main content

larzrpc

JSON-RPC 2.0 over HTTP — client and server, in pure Python. Zero dependencies.

Expose Python functions as a network API and call them from anywhere, using the standard JSON-RPC 2.0 protocol — no framework, no code generation, no dependencies. The server is one decorator and one serve() call; the client calls remote methods as if they were local attributes.

# server.py
from larzrpc import RPCServer
app = RPCServer()

@app.method
def add(a, b):
    return a + b

app.serve("127.0.0.1", 8080)
# client.py
from larzrpc import RPCClient
api = RPCClient("http://127.0.0.1:8080")

api.add(2, 3)                  # 5      (attribute access -> remote call)
api.call("add", a=10, b=1)     # 11     (keyword params)
api.notify("log", "hi")        # fire-and-forget notification

Why

  • Zero dependencies. The client is urllib, the server is http.server — both standard library. Nothing to install.
  • Standard protocol. Real JSON-RPC 2.0: positional and named params, batch requests, notifications, and the canonical error codes — so it interoperates with any compliant peer, not just itself.
  • Ergonomic. Register a method with a decorator; call it as client.method(...). Server errors surface as a real RPCError on the client with the code and data intact.
  • Testable & embeddable. The dispatch core is a pure request -> response function (no sockets), and both client and server take a pluggable transport, so you can wire them together in-process — no network needed.
  • Mount anywhere. Use the built-in threaded server, or the included WSGI app under gunicorn/waitress/larz.

Install

pip install larzrpc

Server

from larzrpc import RPCServer, RPCError

app = RPCServer()

@app.method                       # exposed as "transfer"
def transfer(src, dst, amount):
    if amount <= 0:
        raise RPCError("amount must be positive", code=1001, data={"amount": amount})
    ...
    return {"ok": True}

@app.method(name="account.balance")
def balance(account_id):
    ...

app.methods()                     # ["account.balance", "transfer"]
app.serve("0.0.0.0", 8080)        # threaded HTTP server

Or embed it:

app.dispatch(request_dict)        # -> response dict (pure, no transport)
app.handle_json(raw_json_string)  # -> response JSON (handles batch + parse errors)
app.wsgi                          # a WSGI application

Client

from larzrpc import RPCClient, RPCError

api = RPCClient("http://127.0.0.1:8080")

try:
    api.transfer("a", "b", 100)
except RPCError as e:
    e.code, e.message, e.data     # structured error from the server

Tests

python -m unittest discover -s tests -v   # 20 tests incl. a live localhost round-trip

The Larz stack

Pure-Python, zero-dependency building blocks:

  • larz — money-native web framework
  • larzchain — from-scratch PoW blockchain
  • larzmoney — exact, penny-perfect money
  • larzcrypt — pure-Python cryptography toolkit
  • larzdb — crash-safe embedded database
  • larzagent — zero-dep AI agent framework
  • larzchart — data to inline SVG charts
  • larzmark — Markdown + SEO static sites
  • larztask — durable background job queue
  • larzvault — encrypted secrets manager
  • larzvm — deterministic gas-metered VM
  • larzcache — LRU/TTL/tiered caching
  • larzvalidate — schema validation
  • larzid — decentralized identity
  • larzrpc — this library

License

MIT © larz-scripter

Download files

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

Source Distribution

larzrpc-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

larzrpc-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file larzrpc-0.1.0.tar.gz.

File metadata

  • Download URL: larzrpc-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzrpc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eb51134264777524f1ca17a3524c5f2aa6d14599d175e69671eb8b5770980536
MD5 8812074fa5383638d0b6a5a109dd7596
BLAKE2b-256 5631ccc0584256724e51d6426fc81002037cfa15f8edb295d72eb9cbc00f188f

See more details on using hashes here.

File details

Details for the file larzrpc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzrpc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzrpc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a526b4cc6127a5436efe14d0756cd56cf5efd3120db6b33c1a5fea1c2c1f975
MD5 1f1f63556c7abf3388eae03403041daa
BLAKE2b-256 d83a480ea805e5b31c06b1c9074052a8bc293a10e2e14ed6ae58fbf99394a172

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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