Magic-Wormhole

0.23.0 · active · verified Fri Apr 17

Magic-Wormhole is a Python library and command-line tool for securely transferring arbitrary data (files, directories, or text) between computers using a short, human-speakable 'wormhole code'. It leverages PAKE (Password-Authenticated Key Exchange) for secure key establishment. It is actively maintained at version 0.23.0 with a focus on security, reliability, and ease of use, releasing updates on a moderate cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically send data using the `magic-wormhole` API. Run this script, and it will output a wormhole code. On another machine, a recipient would initiate a transfer by calling `Wormhole.from_code(code)` and then `await w.receive_data()` (or `receive_file()`). The API is asynchronous, requiring `async`/`await` and `asyncio.run()`.

import asyncio
from magic_wormhole.api import Wormhole

async def send_data_example():
    w = Wormhole()
    code = await w.get_code()
    print(f"Your wormhole code is: {code}")
    print("Waiting for recipient to connect...")
    
    # In a real scenario, you'd wait for connection confirmation before sending sensitive data.
    # The 'send_data' or 'send_file' automatically handles the rendezvous.

    data_to_send = b"Hello, magic wormhole!"
    print(f"Sending: '{data_to_send.decode()}'")
    await w.send_data(data_to_send)
    print("Data sent.")
    
    # The wormhole object must be closed to release resources and ensure clean exit.
    await w.close()

if __name__ == "__main__":
    # This runs the asynchronous example using asyncio
    asyncio.run(send_data_example())

view raw JSON →