Skip to main content

Python SDK for MultiversX Warps - Refactored Version

Project description

SDKWarp - MultiversX Warp SDK for Python

A comprehensive Python SDK for creating, managing, and interacting with MultiversX Warps, with an improved and refactored codebase.

Features

  • Full Warp Protocol Support: Create, register, upgrade, and query Warps on the MultiversX blockchain
  • Dynamic Configuration: Load configuration from environment variables, config files, or code
  • Flexible API Design: Use the unified client or individual components based on your needs
  • Transaction Signing: Sign transactions with PEM, keystore, or private key wallets
  • Strong Type Safety: Built with Pydantic for data validation and type checking
  • Async/Await Pattern: Modern asynchronous API for efficient blockchain interactions
  • Web Framework Integrations: Ready-to-use integrations for Flask and FastAPI
  • Improved Code Organization: Logically structured modules with reduced duplication

Installation

# Using pip (basic installation)
pip install sdkwarp

# With web framework integrations
pip install sdkwarp[web]  # Installs both Flask and FastAPI integrations
pip install sdkwarp[flask]  # Only Flask integration
pip install sdkwarp[fastapi]  # Only FastAPI integration

# Using Poetry
poetry add sdkwarp
poetry add sdkwarp -E web  # With web integrations

Quick Start

Using the Dynamic Client (Recommended)

The Client provides a unified interface to all SDK components with dynamic configuration:

import asyncio
from sdkwarp import Client

async def main():
    # Create a client with automatic configuration
    client = Client(
        env="testnet",
        user_address="erd1..."
    )
    
    # Create a Warp
    warp = client.builder.name("my-warp")\
        .title("My First Warp")\
        .description("A simple EGLD transfer Warp")\
        .action_transfer(
            title="Send EGLD",
            description="Send some EGLD to an address"
        )\
        .build()
    
    # Create a transaction
    tx = client.builder.create_inscription_transaction(warp)
    print(f"Transaction created with gas limit: {tx.gas_limit}")
    
    # After sending the transaction and obtaining the hash, you can register it
    await client.init()  # Initialize async components
    tx_hash = "your-transaction-hash"
    register_tx = client.registry.create_warp_register_transaction(tx_hash)

if __name__ == "__main__":
    asyncio.run(main())

Web Framework Integrations

The SDK provides integrations for Flask and FastAPI:

Flask Integration

import asyncio
from flask import Flask
from sdkwarp.config.models import Config, ChainEnv
from sdkwarp.core.registry import Registry, Index
from sdkwarp.web.flask import create_flask_api

# Create a Flask app
app = Flask(__name__)

# Create and set up the API
config = Config(env=ChainEnv.DEVNET, chain_id="D")
registry = Registry(config=config)
index = Index(config=config, registry=registry)

# Initialize components and register with Flask
asyncio.run(registry.init())
asyncio.run(index.init())
api = create_flask_api(config=config, registry=registry, index=index)
api.register_blueprint(app)

# Run the app
app.run(host="0.0.0.0", port=5000)

FastAPI Integration

import asyncio
import uvicorn
from fastapi import FastAPI
from sdkwarp.config.models import Config, ChainEnv
from sdkwarp.core.registry import Registry, Index
from sdkwarp.web.fastapi import create_fastapi_api

# Create a FastAPI app
app = FastAPI(title="Warp SDK API")

# Create and set up the API
config = Config(env=ChainEnv.DEVNET, chain_id="D")
registry = Registry(config=config)
index = Index(config=config, registry=registry)

# Initialize components and register with FastAPI
asyncio.run(registry.init())
asyncio.run(index.init())
api = create_fastapi_api(config=config, registry=registry, index=index)
api.register(app)

# Run the app
uvicorn.run(app, host="0.0.0.0", port=8000)

For more detailed examples, see the examples directory.

Project Structure

The SDK follows a clean, modular structure:

sdkwarp/
├── config/           # All configuration-related code
│   ├── loader.py     # Configuration loading logic
│   ├── models.py     # Pydantic models for configuration
│   └── constants.py  # Environment-specific constants
├── utils/            # Utility functions
│   ├── codec.py      # Encoding/decoding utilities
│   ├── validation.py # Validation helpers
│   ├── formatting.py # String formatting utilities
│   └── helpers.py    # General purpose helpers
├── core/             # Core functionality
│   ├── builder/      # Warp building components
│   ├── registry/     # Registry interaction
│   ├── transaction/  # Transaction handling
│   └── contracts/    # Contract interaction
├── web/              # Web framework integrations
│   ├── flask/        # Flask integration
│   └── fastapi/      # FastAPI integration
├── examples/         # Example implementations
│   ├── flask_example.py    # Flask integration example
│   └── fastapi_example.py  # FastAPI integration example
├── client.py         # Main client interface
└── cli.py            # Command-line interface

Development

To set up for development:

# Clone the repository
git clone https://github.com/yourusername/sdkwarp.git
cd sdkwarp

# Install dependencies with development extras
pip install -e ".[dev,web]"

# Or using Poetry
poetry install -E dev -E web

# Run tests
pytest

# Run examples
python -m sdkwarp.examples.flask_example
python -m sdkwarp.examples.fastapi_example

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

sdkwarp-0.1.0.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

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

sdkwarp-0.1.0-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

Details for the file sdkwarp-0.1.0.tar.gz.

File metadata

  • Download URL: sdkwarp-0.1.0.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for sdkwarp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cbab1e581ec238a94c5a83f8ff3015cb5fd093afe2e31bc99a0522f52390e26f
MD5 7d4a0d48046bb53e2c67095a90fef5cc
BLAKE2b-256 2dd18606798d64b75229cc41d3b220ba0287376463ef6f16c551c89ee856a1a5

See more details on using hashes here.

File details

Details for the file sdkwarp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sdkwarp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for sdkwarp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71e016b064d63b9125b645a2cf368c4a14f1ec02307d50fabf1d23c58f857621
MD5 5feef0a01f4d61aeb938c59ed6777d18
BLAKE2b-256 2fa006333925153763d0ae04ce421d2d7765b2edee65a5c21d9df22fa6ac6a8c

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