i2psam
Async Python client for the I2P SAM (Simple Anonymous Messaging) protocol.
i2psam provides:
- connection management with retry/backoff
- SAM handshake, session creation, and command helpers
- stream connect/accept/forward helpers
- datagram send/receive helpers
- optional package logging
Requirements
- Python
>=3.10 - Running I2P router with SAM enabled
- default SAM TCP port:
7656 - default SAM UDP port:
7655
- default SAM TCP port:
Installation
From pip
pip install i2psam
For UV
uv add i2psam
From source:
pip install .
For development:
pip install -e .
Quick Start
import asyncio
from i2psam import SAMClient
async def main():
sam = SAMClient()
# Ask SAM bridge to generate destination keys
keys = await sam.dest_generate()
print("Public destination:", keys.pub)
# Create STREAM session
async with sam.session("my-session", destination=keys.priv) as sess:
print("Session created:", sess.session_id)
asyncio.run(main())
Configuration
from i2psam import SAMClient, SAMConfig
cfg = SAMConfig(
host="127.0.0.1",
port=7656,
udp_port=7655,
connection_timeout=10,
connection_retries=3,
exponential_backoff=False,
)
sam = SAMClient(cfg)
STREAM Example
Accept inbound connection
async with sam.session("listener", destination=keys.priv) as sess:
async with sess.accept_stream() as (peer_dest, conn):
data = await conn.read_line()
print("from", peer_dest, data)
Connect to peer
peer_dest = "<peer public destination>"
async with sam.session("dialer", destination="TRANSIENT") as sess:
async with sess.connect_stream(peer_dest) as conn:
await conn.write("hello from i2psam")
Full chat example: examples/chat.py
DATAGRAM Example
async with sam.session("dgram", destination=keys.priv) as sess:
async with sess.create_datagram() as dg:
dg.sendto("<peer destination>", b"ping")
sender, payload = await dg.recv()
print(sender, payload)
Low-level Command API
You can send command models directly:
from i2psam import SAMClient
from i2psam.commands.commands import HelloVersion
reply = await SAMClient().request(HelloVersion(MIN="3.0", MAX="3.3"))
print(reply.version)
Or send raw SAM lines:
raw = await SAMClient().raw_request("HELLO VERSION MIN=3.0 MAX=3.3")
print(raw)
Logging
Library logging is silent by default (NullHandler).
Enable logs:
from i2psam import configure_logging
configure_logging("DEBUG")
Create named logger if needed:
from i2psam import get_logger
log = get_logger("custom")
log.info("hello")
Errors
Common exceptions:
SAMErrorSAMClientErrorSAMSessionErrorSAMStreamErrorSAMDatagramError
Use them to handle bridge/network/protocol failures.
Running Tests
pytest -q
Release files for i2psam 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| i2psam-1.0.0.tar.gz | 33.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| i2psam-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.4 kB
Release files / i2psam-1.0.0.tar.gz
| Download URL | i2psam-1.0.0.tar.gz |
|---|---|
| Size | 33.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
750671226e1387a283cee85d0f45e0b93e3d8b0cb19a894758bb503050f0528d
|
|
BLAKE2b-256 checksum How to use checksums |
077ba2309019209e10d2683b5f419cac3b05092836cddcb2448a74a5b043fdba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 8, 2026.
Transparency logRelease files / i2psam-1.0.0-py3-none-any.whl
| Download URL | i2psam-1.0.0-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53a3821e5115b55ca2165ae8c10ea04e3beecd33764d72f8e33374113a1a6d80
|
|
BLAKE2b-256 checksum How to use checksums |
98d2a886a09c271a35d24d885635ab7fac77f9c0277c0d8cbb0f8c875a8085be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 8, 2026.
Transparency log