Skip to main content

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdk_python-0.7.0.tar.gz (14.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdk_python-0.7.0-py3-none-any.whl (15.0 MB view details)

Uploaded Python 3

File details

Details for the file mdk_python-0.7.0.tar.gz.

File metadata

  • Download URL: mdk_python-0.7.0.tar.gz
  • Upload date:
  • Size: 14.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mdk_python-0.7.0.tar.gz
Algorithm Hash digest
SHA256 8f47344f134fd5a307d379d4c3a2437a5730d2c14ab370ffa5941ef6662a5d60
MD5 98d7d73b18b1e600b6886604fc846913
BLAKE2b-256 a373942323f2fe3a9fef20856d61383fabd136b4fc442459de39fabfe2a9fc3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdk_python-0.7.0.tar.gz:

Publisher: package-mdk-bindings.yml on marmot-protocol/mdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mdk_python-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: mdk_python-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mdk_python-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ac8fdd13849a1a8b77d081fe7d9a6a869883e9b5cc1c9f2dfa7c20c969b1967
MD5 005d8b375e58dbfc1844e9a6d818ee5d
BLAKE2b-256 5e13e423c02ce476409a842938624111055d68d1d8721a40b0eb7103f4787df7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdk_python-0.7.0-py3-none-any.whl:

Publisher: package-mdk-bindings.yml on marmot-protocol/mdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page