Async Python client for the I2P SAM (Simple Anonymous Messaging) protocol.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file i2psam-1.0.0.tar.gz.
File metadata
- Download URL: i2psam-1.0.0.tar.gz
- Upload date:
- Size: 33.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
750671226e1387a283cee85d0f45e0b93e3d8b0cb19a894758bb503050f0528d
|
|
| MD5 |
2dde624c68b1bd1cfbad884d0a02d2e3
|
|
| BLAKE2b-256 |
077ba2309019209e10d2683b5f419cac3b05092836cddcb2448a74a5b043fdba
|
Provenance
The following attestation bundles were made for i2psam-1.0.0.tar.gz:
Publisher:
release.yml on AstralMortem/i2psam
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
i2psam-1.0.0.tar.gz -
Subject digest:
750671226e1387a283cee85d0f45e0b93e3d8b0cb19a894758bb503050f0528d - Sigstore transparency entry: 1059693638
- Sigstore integration time:
-
Permalink:
AstralMortem/i2psam@27bb604764a5c05b7513d82e8c30b02095a335c6 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/AstralMortem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@27bb604764a5c05b7513d82e8c30b02095a335c6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file i2psam-1.0.0-py3-none-any.whl.
File metadata
- Download URL: i2psam-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53a3821e5115b55ca2165ae8c10ea04e3beecd33764d72f8e33374113a1a6d80
|
|
| MD5 |
64faa624693a5642906b41a5f0601f7c
|
|
| BLAKE2b-256 |
98d2a886a09c271a35d24d885635ab7fac77f9c0277c0d8cbb0f8c875a8085be
|
Provenance
The following attestation bundles were made for i2psam-1.0.0-py3-none-any.whl:
Publisher:
release.yml on AstralMortem/i2psam
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
i2psam-1.0.0-py3-none-any.whl -
Subject digest:
53a3821e5115b55ca2165ae8c10ea04e3beecd33764d72f8e33374113a1a6d80 - Sigstore transparency entry: 1059693643
- Sigstore integration time:
-
Permalink:
AstralMortem/i2psam@27bb604764a5c05b7513d82e8c30b02095a335c6 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/AstralMortem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@27bb604764a5c05b7513d82e8c30b02095a335c6 -
Trigger Event:
push
-
Statement type: