Python bindings for Marmot Development Kit - A Rust implementation of the Marmot Protocol for secure, decentralized group messaging.
Project description
[!NOTE] This is a generic documentation, read Python-specific docs.
MDK Bindings for Python
Language bindings for the Marmot Development Kit - bringing decentralized, encrypted group messaging to your favorite language. These bindings include all features in mdk, if you'd like smaller bindings without features such as MIP-04, or you'd like bindings for other languages, please let us know by opening an issue!
What is MDK?
MDK combines MLS (Messaging Layer Security) Protocol (the gold standard for group crypto) with Nostr.
You get real end-to-end encryption using MLS with forward secrecy and post-compromise security. Since it's built on Nostr's distributed relay network, there's no server needed. The group functionality actually works with proper secure member management and encrypted everything. Keys rotate automatically so you can't mess anything up, and it even protects your metadata so your chatter patterns stay private.
How It Actually Works
We use UniFFI to bridge the Rust MDK core to your language without the usual FFI headaches. Everything persists in a SQLite database file you specify when you create an MDK instance, holding all your groups, messages, keys, and state. The instance is internally mutexed for thread safety, but if you can avoid it don't share MDK instances across threads.
Core Concepts
The MDK instance is your main entry point, just point it at a SQLite file and it manages all your groups, messages, key packages, and everything else. Groups are MLS conversations with unique hex IDs, names, descriptions, member lists, and associated Nostr relays. Each group has admins who handle adding and removing key packages.
Messages are MLS-encrypted group chatter that get auto-decrypted when you retrieve them, when someone adds you to a group, you get a welcome message containing all the keys and state you need to decrypt everything and participate.
The API You'll Actually Use
Getting started is simple: first initialize your platform's keyring store (see platform setup), then create your MDK instance with new_mdk("/path/to/your/database.db", "com.example.myapp", "mdk.db.key.default"). MDK automatically handles encryption key generation and secure storage in your platform's keyring (Keychain on iOS/macOS, Keystore on Android, etc.). If you need to manage keys yourself, use new_mdk_with_key() with a 32-byte key. For development only, you can use new_mdk_unencrypted("/path/to/database.db") but never ship that to production. For key packages, you'll want to create one with your preferred relays using mdk.create_key_package(), which gives you a hex key package and tags for your Nostr event. When others send you their key package events, parse them with mdk.parse_key_package() so you can add them later. Check for invites using mdk.get_pending_welcomes() and join groups with mdk.accept_welcome().
For group management, start your own group with mdk.create_group() - you'll need your creator pubkey, initial members, metadata, relays, and admin list. It returns the group object and welcome messages for your initial members. Adding people requires admin privileges and their key package events via mdk.add_members(). Remove troublemakers with mdk.remove_members() using their pubkeys, or update group metadata like name and description with mdk.update_group_metadata().
Send encrypted messages with mdk.create_message(), specifying the group, your pubkey, content, and message kind - it returns an encrypted Nostr event you can publish to your relays. Retrieve message history with mdk.get_messages() where everything's auto-decrypted. When you pull events from Nostr relays, process them using mdk.process_message() which tells you if it's new, a duplicate, or if something goes wrong during processing.
Data Models
Group objects contain the mls_group_id as a hex string, plus the name you gave it, description with the group vibes, list of relay URLs, an array of pubkeys for the admins, and a creation timestamp. Messages have the event_id from Nostr, the mls_group_id they belong to, the sender_public_key, the actual decrypted content, a numeric kind for message type, and the created_at timestamp. Welcome messages include the raw welcome_json invite data, the group_name and group_description so you know what you're joining, and the sender_public_key of your inviter.
What's Next
If you want to go deeper, check out the Marmot Protocol Spec for the full details, MLS RFC 9420 for the crypto foundation, the Nostr Protocol for the network layer, and UniFFI Docs if you're curious about how the bindings work under the hood. But you don't have to!
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 mdk_python-0.8.0.tar.gz.
File metadata
- Download URL: mdk_python-0.8.0.tar.gz
- Upload date:
- Size: 14.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baed7617df49d9248d60078d5201e2ef14b58d0b7f0a57cbe7baf9328ef859aa
|
|
| MD5 |
3522446bc214304112168f6ad401b8f3
|
|
| BLAKE2b-256 |
b977d2b82f3b8991631239591c5a416f488eb2f75de3e993b9d14f9e1288716d
|
Provenance
The following attestation bundles were made for mdk_python-0.8.0.tar.gz:
Publisher:
package-mdk-bindings.yml on marmot-protocol/mdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdk_python-0.8.0.tar.gz -
Subject digest:
baed7617df49d9248d60078d5201e2ef14b58d0b7f0a57cbe7baf9328ef859aa - Sigstore transparency entry: 1437403708
- Sigstore integration time:
-
Permalink:
marmot-protocol/mdk@c1ee17ec4c811f28d5c1ffdbd9284121dda214ab -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/marmot-protocol
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package-mdk-bindings.yml@c1ee17ec4c811f28d5c1ffdbd9284121dda214ab -
Trigger Event:
push
-
Statement type:
File details
Details for the file mdk_python-0.8.0-py3-none-any.whl.
File metadata
- Download URL: mdk_python-0.8.0-py3-none-any.whl
- Upload date:
- Size: 14.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19d51a84da42c3766d8c3af2763caaee2afe086ca5c7f81a566c49a453c7dc9a
|
|
| MD5 |
e35ee9665d75fec9e2d6a393229a6462
|
|
| BLAKE2b-256 |
c8afebc60cc290b4e4a2f97b90304493a818c5eebdf82d1fc80da6b66123ea2e
|
Provenance
The following attestation bundles were made for mdk_python-0.8.0-py3-none-any.whl:
Publisher:
package-mdk-bindings.yml on marmot-protocol/mdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdk_python-0.8.0-py3-none-any.whl -
Subject digest:
19d51a84da42c3766d8c3af2763caaee2afe086ca5c7f81a566c49a453c7dc9a - Sigstore transparency entry: 1437403713
- Sigstore integration time:
-
Permalink:
marmot-protocol/mdk@c1ee17ec4c811f28d5c1ffdbd9284121dda214ab -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/marmot-protocol
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package-mdk-bindings.yml@c1ee17ec4c811f28d5c1ffdbd9284121dda214ab -
Trigger Event:
push
-
Statement type: