Skip to main content

capyy — tiny encrypted JSON-over-TCP APIs

Call a function in another Python program — on the same machine, on your Wi-Fi, or across the internet — with one line of code. Zero dependencies, Python 3.9+, encrypted with TLS by default.

pip install capyy

The package is published as capyy, but you import it as capy. Error messages are in French (the library was written for French speakers), and the full documentation, with examples, is at libs.zazac.link/capy.

Quick start

# server.py
import capy

api = capy.Server(4000)

@api.action("hello")
def hello(name="you"):
    return {"message": f"Hello {name}!"}

api.run()
# client.py
import capy

print(capy.call("localhost", 4000, "hello", name="Alice"))   # {'message': 'Hello Alice!'}
  • An action returns a dict, or JSON written as text with capy.json('{"text": "Hello"}').
  • Errors raised on the server come back as {"erreur": "..."} (unknown action, bad parameters, exceptions).
  • capy.call raises ConnectionError when the server does not answer.

Reading a response

reply = {"city": "Paris", "temp": "18.5", "days": [{"name": "monday"}, {"name": "tuesday"}]}

capy.get(reply, "days.1.name")          # "tuesday"  (paths go through dicts and lists)
capy.get(reply, "wind", default=0)      # 0
capy.to_float(reply, "temp")            # 18.5
capy.to_int("42"), capy.to_bool("yes")  # 42, True

to_str, to_int, to_float, to_bool, to_list and to_dict raise a ValueError that says exactly what could not be converted.

Encryption (TLS)

Everything is encrypted by default, with nothing to configure.

  • Each machine running a server creates its own certificate on first launch (~/.capy, using openssl) and prints its fingerprint.
  • Like SSH, a client remembers a server's fingerprint the first time (~/.capy/known_hosts.json) and raises capy.SecurityError if it ever changes.
  • The server logs every request, but never secrets: parameters whose name contains password, pwd, mdp, secret or token are shown as "***".
  • Use tls=False on both sides to talk in clear (faster on localhost).

capy.wifi — find each other on the same network

import capy.wifi

api = capy.wifi.Server("living-room")   # announces itself on the LAN, port chosen automatically
...
capy.wifi.call("living-room", "light", on=False)   # from any device on the same Wi-Fi
capy.wifi.scan()                                    # {'living-room': ('192.168.1.42', 51234)}

capy.network — across the internet, through a relay

A machine behind a home router cannot be reached from the internet, so capy.network goes through a relay running on a machine with a public IP (a VPS). Servers connect to it and register a name; clients call that name. Everything is encrypted, and the connection is kept open between calls.

python3 -m capy.network 3879 my-secret-key      # on the VPS (open the port in its firewall)
import capy.network

capy.network.use("my-vps.example:3879", key="my-secret-key")
capy.network.Server("home").run()        # at home, even behind a router
capy.network.call("home", "temperature") # from anywhere

License

MIT

Metadata

Release files for capyy 0.3.2

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

Source distribution (sdist)

Source distribution for capyy 0.3.2
File Size Uploaded Provenance
capyy-0.3.2.tar.gz 19.9 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 38.2 kB

Release files / capyy-0.3.2.tar.gz

Download URL capyy-0.3.2.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
eb33e751ac717d66a469a2c985f60c4cdf4675c46b5f2727b484f041ee45b718
BLAKE2b-256 checksum
How to use checksums
9b7f81705343d76ef0fa633ea396f17683abb02f04318d2a063d68b1b49c3cc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / capyy-0.3.2-py3-none-any.whl

Download URL capyy-0.3.2-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
857be8b97e686ea9378d96e663b8b4be9701c43d75909b75ce8f9abb400b26b7
BLAKE2b-256 checksum
How to use checksums
692b481a06d86d06a79981ac9af64fe0a39e7caa28109adebc1930a53ac7dd86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for capyy 0.3.2

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.

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