Skip to main content

python CFFI bindings for the olm cryptographic ratchet library

Reason this release was yanked:

Unusable file

Project description

python-olm

Python bindings for Olm.

The specification of the Olm cryptographic ratchet which is used for peer to peer sessions of this library can be found here.

The specification of the Megolm cryptographic ratchet which is used for group sessions of this library can be found here.

An example of the implementation of the Olm and Megolm cryptographic protocol can be found in the Matrix protocol for which the implementation guide can be found here.

The full API reference can be found here.

Installation instructions

To install from the source package, you will need:

  • cmake (recommended) or GNU make
  • a C/C++ compiler

You can then run pip install python-olm.

This should work in UNIX-like environments, including macOS, and may work in other environments too, but is known to not work yet in Windows.

Accounts

Accounts create and hold the central identity of the Olm protocol, they consist of a fingerprint and identity key pair. They also produce one time keys that are used to start peer to peer encrypted communication channels.

Account Creation

A new account is created with the Account class, it creates a new Olm key pair. The public parts of the key pair are available using the identity_keys property of the class.

>>> alice = Account()
>>> alice.identity_keys
{'curve25519': '2PytGagXercwHjzQETLcMa3JOsaU2qkPIESaqoi59zE',
 'ed25519': 'HHpOuFYdHwoa54GxSttz9YmaTmbuVU3js92UTUjYJgM'}

One Time keys

One time keys need to be generated before people can start an encrypted peer to peer channel to an account.

>>> alice.generate_one_time_keys(1)
>>> alice.one_time_keys
{'curve25519': {'AAAAAQ': 'KiHoW6CIy905UC4V1Frmwr3VW8bTWkBL4uWtWFFllxM'}}

After the one time keys are published they should be marked as such so they aren't reused.

>>> alice.mark_keys_as_published()
>>> alice.one_time_keys
{'curve25519': {}}

Pickling

Accounts should be stored for later reuse, storing an account is done with the pickle method while the restoring step is done with the from_pickle class method.

>>> pickle = alice.pickle()
>>> restored = Account.from_pickle(pickle)

Sessions

Sessions are used to create an encrypted peer to peer communication channel between two accounts.

Session Creation

>>> alice = Account()
>>> bob = Account()
>>> bob.generate_one_time_keys(1)
>>> id_key = bob.identity_keys["curve25519"]
>>> one_time = list(bob.one_time_keys["curve25519"].values())[0]
>>> alice_session = OutboundSession(alice, id_key, one_time)

Encryption

After an outbound session is created an encrypted message can be exchanged:

>>> message = alice_session.encrypt("It's a secret to everybody")
>>> message.ciphertext
'AwogkL7RoakT9gnjcZMra+y39WXKRmnxBPEaEp6OSueIA0cSIJxGpBoP8YZ+CGweXQ10LujbXMgK88
xG/JZMQJ5ulK9ZGiC8TYrezNYr3qyIBLlecXr/9wnegvJaSFDmWDVOcf4XfyI/AwogqIZfAklRXGC5b
ZJcZxVxQGgJ8Dz4OQII8k0Dp8msUXwQACIQvagY1dO55Qvnk5PZ2GF+wdKnvj6Zxl2g'
>>> message.message_type
0

After the message is transfered, bob can create an InboundSession to decrypt the message.

>>> bob_session = InboundSession(bob, message)
>>> bob_session.decrypt(message)
"It's a secret to everybody"

Pickling

Sessions like accounts can be stored for later use the API is the same as for accounts.

>>> pickle = session.pickle()
>>> restored = Session.from_pickle(pickle)

Group Sessions

Group Sessions are used to create a one-to-many encrypted communication channel. The group session key needs to be shared with all participants that should be able to decrypt the group messages. Another thing to notice is that, since the group session key is ratcheted every time a message is encrypted, the session key should be shared before any messages are encrypted.

Group Session Creation

Group sessions aren't bound to an account like peer-to-peer sessions so their creation is straightforward.

>>> alice_group = OutboundGroupSession()
>>> bob_inbound_group = InboundGroupSession(alice_group.session_key)

Group Encryption

Group encryption is pretty simple. The important part is to share the session key with all participants over a secure channel (e.g. peer-to-peer Olm sessions).

>>> message = alice_group.encrypt("It's a secret to everybody")
>>> bob_inbound_group.decrypt(message)
("It's a secret to everybody", 0)

Pickling

Pickling works the same way as for peer-to-peer Olm sessions.

>>> pickle = session.pickle()
>>> restored = InboundGroupSession.from_pickle(pickle)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

python3_olm-3.2.17-cp314-cp314-manylinux_2_39_x86_64.whl (314.6 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

python3_olm-3.2.17-cp313-cp313-manylinux_2_39_x86_64.whl (314.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

python3_olm-3.2.17-cp312-cp312-manylinux_2_39_x86_64.whl (247.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

python3_olm-3.2.17-cp311-cp311-manylinux_2_39_x86_64.whl (311.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

python3_olm-3.2.17-cp310-cp310-manylinux_2_39_x86_64.whl (311.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.39+ x86-64

File details

Details for the file python3_olm-3.2.17-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: python3_olm-3.2.17-cp314-cp314-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 314.6 kB
  • Tags: CPython 3.14, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python3_olm-3.2.17-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 ce2f3bbd859fe0b08b5aaab902c6816ce0a47d1b47e40315ac3b31107166a205
MD5 ec341ffc9e481910a119c4357039773d
BLAKE2b-256 870af6984dfe8a34dfa9d5124d7249af4f39f95791464df5a3121bdfc39eddec

See more details on using hashes here.

File details

Details for the file python3_olm-3.2.17-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: python3_olm-3.2.17-cp313-cp313-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 314.6 kB
  • Tags: CPython 3.13, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python3_olm-3.2.17-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 276ab5dee7a656421f49ec94ed37b6ecfaab405d0bc8126bfa3080bb317cd28f
MD5 fb14c43e215f85d6cff53f1cde2c6c1c
BLAKE2b-256 3bcaed9f271e3665177d52865fcfa580e41537da354628ce27dfa39a3a6e6722

See more details on using hashes here.

File details

Details for the file python3_olm-3.2.17-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: python3_olm-3.2.17-cp312-cp312-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 247.5 kB
  • Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python3_olm-3.2.17-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 d37c902c940e27d29b5d6da7ae66dceacbb3f4267bec28ff75cb017c5bf0596f
MD5 d930918c58607a8cba1b4fc3634beb3c
BLAKE2b-256 1a1442bb25b54e3f0e01c672c484c0c4e9a4fb9e79c5715fcb91baeaae7aafe9

See more details on using hashes here.

File details

Details for the file python3_olm-3.2.17-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: python3_olm-3.2.17-cp311-cp311-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 311.2 kB
  • Tags: CPython 3.11, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python3_olm-3.2.17-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 15af1219b1ece71f79dbfbb699b5ab03e27595706b3a835b0e8802363b7e61e5
MD5 716f2502a6c921e814b06fa8dbe07833
BLAKE2b-256 088f0b48d266509dd723177f122577b37c9657348f7db91534d65b2f7fec4de0

See more details on using hashes here.

File details

Details for the file python3_olm-3.2.17-cp310-cp310-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: python3_olm-3.2.17-cp310-cp310-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 311.2 kB
  • Tags: CPython 3.10, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for python3_olm-3.2.17-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 4e224184fd3d0004187d71b1625830b5625800bf9a12c0fb60f38b3f65a75e98
MD5 1ae51749858a909a4b4be03b8eabcef4
BLAKE2b-256 4cfb8a7e4aa6dced91139fae7f332999d7764e393aad13d8a8581e2bbbe0e7c0

See more details on using hashes here.

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