Introducing the Lit Python SDK

The Lit Python SDK is now live.

Introducing the Lit Python SDK

Weโ€™re excited to announce that the Lit Python SDK is now live, making it easier than ever for developers to integrate Lit Protocol into their Python-based applications. This new SDK provides streamlined access to Litโ€™s decentralized encryption, signing, and compute functionality, opening the door for more versatile and secure Web3 applications.

The Python SDK can be accessed here: https://pypi.org/project/lit-python-sdk/ 

Additionally, a Python adaptation of the Lit Agent Wallet has been released as well. You can access the Python equivalent here: https://pypi.org/project/agentWallet-python/ 

Supported Functionality

With the release of the Lit Python SDK (lit-python-sdk) and Agent Wallet Python SDK (agentWallet-python), developers can now perform:

  • ๐Ÿ”‘ Encryption and Decryption: Securely encrypt content with Litโ€™s key management network and decrypt only when access conditions are met.
  • ๐Ÿ”ฅ Programmable Key Pair (PKP) Generation and Message Signing: Generate Lit PKPs and use them for general message passing and transacting on-chain. 
  • โšก Lit Action Execution: Create and execute Lit Actions for a variety of use cases, such as fetching off-chain data, automating interactions, using dependencies, and more. 
  • ๐Ÿค– Agent Wallet Functionality: Use the Lit Agent Wallet natively in Python.

Getting Started

Getting started is as simple as installing the relevant SDK via pip:

pip install lit-python-sdk

pip install agentWallet-python

Simple Usage Examples

๐Ÿ”น Perform Encryption and Decryption

# Encrypt a string
encrypt_result = client.encrypt_string(
    data_to_encrypt="Hello, World!",
    access_control_conditions=access_control_conditions
)

# The encrypt_result contains:
# - ciphertext: the encrypted string
# - dataToEncryptHash: hash of the original data

# Decrypt the string
decrypt_result = client.decrypt_string(
    ciphertext=encrypt_result["ciphertext"],
    data_to_encrypt_hash=encrypt_result["dataToEncryptHash"],
    chain="ethereum",
    access_control_conditions=access_control_conditions,
    session_sigs=session_sigs
)

๐Ÿ”น Sign a Message

# Sign a message
to_sign_hex = "0xadb20420bde8cda6771249188817098fca8ccf8eef2120a31e3f64f5812026bf"
hex_str = to_sign_hex[2:] if to_sign_hex.startswith("0x") else to_sign_hex
to_sign = [int(hex_str[i:i+2], 16) for i in range(0, len(hex_str), 2)]

signature = client.pkp_sign(
    pub_key=pkp["publicKey"],
    to_sign=to_sign,
    session_sigs=session_sigs
)

๐Ÿ”น PKP Generation

# Mint a new PKP
mint_result = client.mint_with_auth(
    auth_method={
        "authMethodType": 1,  # EthWallet
        "accessToken": auth_sig_result["authSig"],
    },
    scopes=[1]
)
pkp = mint_result["pkp"]

๐Ÿ”น Executing a Lit Action

# Execute the code
js_code = """
(async () => {
    console.log("Testing executeJs endpoint");
    Lit.Actions.setResponse({response: "Test successful"});
})()
"""

result = client.execute_js(
    code=js_code,
    js_params={},
    session_sigs=session_sigs
)

Looking Ahead

Weโ€™re actively working on adding additional functionality to the Python SDK and are focused on making ongoing performance optimizations. 

๐Ÿ’ก Join the Discussion: Have ideas, feedback, or questions? Join the Lit Builders Circle on Telegram and follow us on X to stay updated on the latest developments. 

๐Ÿš€ Build with Lit today: Check out the following resources to kick off your development journey: