Standalone Ultra-Secure Communication Protocol - Python SDK
Project description
Sibna Protocol — Python SDK
Python SDK for the Sibna encrypted communication protocol.
Before You Start — What You Need
This SDK does not work standalone. It requires a compiled native library built from the sibna-protc Rust project:
| OS | Required File |
|---|---|
| Windows | sibna_core.dll |
| Linux | libsibna_core.so |
| macOS | libsibna_core.dylib |
To build the library:
cd sibna-protc/core
cargo build --release --features ffi
# Output is in: target/release/
Then copy the resulting file into the same sibna/ folder as this SDK.
Installation
# External dependencies (this SDK is NOT zero-dependencies)
pip install cryptography # For Identity + signature verification
pip install requests # For the sync HTTP client
pip install aiohttp # For async + WebSocket
What This SDK Does
sibna (core — requires the compiled native library)
| Function / Class | What it does |
|---|---|
is_available() |
Checks if the native library is loaded |
generate_key() |
Generates a random 32-byte key |
encrypt(key, data) |
Encrypts data (ChaCha20-Poly1305) |
decrypt(key, data) |
Decrypts data |
random_bytes(n) |
Generates cryptographically secure random bytes |
Context() |
Manages identity and encrypted sessions |
Context.generate_identity() |
Generates an identity keypair (Ed25519 + X25519) |
Context.generate_prekey_bundle() |
Generates a bundle to upload to the prekey server |
Context.perform_handshake(...) |
Runs X3DH and creates a Double Ratchet session |
Context.session_encrypt(...) |
Encrypts a message over an existing session |
Context.session_decrypt(...) |
Decrypts a message |
sibna.client (networking — requires requests / aiohttp)
| Class | What it does |
|---|---|
Identity |
Ed25519 keypair for server authentication |
SibnaClient |
Synchronous HTTP client |
AsyncSibnaClient |
Async + WebSocket client |
Basic Example — Simple Encryption
import sibna
# Check the library is available
if not sibna.is_available():
raise RuntimeError("Native library not found. Build it from sibna-protc first.")
# Encrypt and decrypt
key = sibna.generate_key() # Random 32-byte key
ct = sibna.encrypt(key, b"Hello")
pt = sibna.decrypt(key, ct)
assert pt == b"Hello"
# With associated data (authenticated but not encrypted)
ct = sibna.encrypt(key, b"Secret", associated_data=b"context-header")
pt = sibna.decrypt(key, ct, associated_data=b"context-header")
Advanced Example — Double Ratchet Session
import sibna
# On Alice's device
alice_ctx = sibna.Context(password=b"AlicePass1!")
alice_ed, alice_x = alice_ctx.generate_identity()
alice_bundle = alice_ctx.generate_prekey_bundle()
# On Bob's device
bob_ctx = sibna.Context(password=b"BobPass1!")
bob_ed, bob_x = bob_ctx.generate_identity()
bob_bundle = bob_ctx.generate_prekey_bundle()
# Alice initiates the handshake with Bob
alice_ctx.perform_handshake(
peer_id=bob_ed, # Bob's identity key (used as session ID)
peer_bundle=bob_bundle, # Bob's bundle (fetched from prekey server)
initiator=True,
)
# Bob accepts the handshake from Alice
bob_ctx.perform_handshake(
peer_id=alice_ed,
peer_bundle=alice_bundle,
initiator=False,
)
# Alice encrypts
ciphertext = alice_ctx.session_encrypt(bob_ed, b"Hello Bob!")
# Bob decrypts
plaintext = bob_ctx.session_decrypt(alice_ed, ciphertext)
assert plaintext == b"Hello Bob!"
Example — HTTP Client
from sibna.client import SibnaClient
import sibna
# Set up encryption context
ctx = sibna.Context()
ctx.generate_identity()
bundle = ctx.generate_prekey_bundle()
# Connect to server
client = SibnaClient(server="http://localhost:8080")
client.generate_identity() # Separate identity for server auth
client.authenticate() # JWT challenge-response flow
client.upload_prekey(bundle.hex())
# Send an encrypted message (payload is pre-encrypted by Context)
ciphertext = ctx.session_encrypt(b"peer_id_here", b"Hello!")
client.send_message(
recipient_id="peer_identity_hex",
payload_hex=ciphertext.hex(),
)
# Receive messages
messages = client.fetch_inbox()
for msg in messages:
plaintext = ctx.session_decrypt(
bytes.fromhex(msg["sender_id"]),
bytes.fromhex(msg["payload_hex"]),
)
print(plaintext.decode())
Common Errors
| Error | Cause | Fix |
|---|---|---|
LibraryNotFoundError |
Native library not found | Build sibna-protc with Rust |
SibnaError(13) |
Tampered data or wrong key | Check key and associated_data |
SibnaError(7) |
Session does not exist | Call perform_handshake() first |
SibnaError(10) |
Weak password | Use a password with uppercase, lowercase, and digits |
MissingDependencyError |
Python package not installed | pip install cryptography requests aiohttp |
A Note on Dependencies
This SDK is not zero-dependencies:
__init__.pyrequires the compiled Rust native libraryclient.pyrequirescryptography,requests, andaiohttp
The Rust core itself has no runtime dependencies once compiled.
License
Apache-2.0
Project details
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 sibna-1.5.0.tar.gz.
File metadata
- Download URL: sibna-1.5.0.tar.gz
- Upload date:
- Size: 778.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
984b40e7c5805142ff64af096383192ced3d6e8667e4c51395192cf45941eb73
|
|
| MD5 |
f40b2fb048afba718264f94306fa8fcb
|
|
| BLAKE2b-256 |
cb50ec04b1d273fd3df810dbd2faa7a62ef0be03f214a3c8beb9b4ef51d76874
|
Provenance
The following attestation bundles were made for sibna-1.5.0.tar.gz:
Publisher:
workflow.yml on SibnaOfficial/libsa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sibna-1.5.0.tar.gz -
Subject digest:
984b40e7c5805142ff64af096383192ced3d6e8667e4c51395192cf45941eb73 - Sigstore transparency entry: 1207582103
- Sigstore integration time:
-
Permalink:
SibnaOfficial/libsa@374469b3390deea45e0818bae57079e09f86667d -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/SibnaOfficial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@374469b3390deea45e0818bae57079e09f86667d -
Trigger Event:
push
-
Statement type:
File details
Details for the file sibna-1.5.0-py3-none-any.whl.
File metadata
- Download URL: sibna-1.5.0-py3-none-any.whl
- Upload date:
- Size: 780.1 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 |
2cf6af8a236baf52669951c43779d3cf616163cfd78de96e65584fff43ffc742
|
|
| MD5 |
34c0af3b6086e6a00635d054217f8045
|
|
| BLAKE2b-256 |
addc53ee353d5ea4a8fc1bcd8a5eea0f5d2f2cee8e6c36f63493096b5e4abe3b
|
Provenance
The following attestation bundles were made for sibna-1.5.0-py3-none-any.whl:
Publisher:
workflow.yml on SibnaOfficial/libsa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sibna-1.5.0-py3-none-any.whl -
Subject digest:
2cf6af8a236baf52669951c43779d3cf616163cfd78de96e65584fff43ffc742 - Sigstore transparency entry: 1207582153
- Sigstore integration time:
-
Permalink:
SibnaOfficial/libsa@374469b3390deea45e0818bae57079e09f86667d -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/SibnaOfficial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@374469b3390deea45e0818bae57079e09f86667d -
Trigger Event:
push
-
Statement type: