Skip to main content

Python API for interacting with MUD Autonomous Worlds

Project description

mud-aw.py 🧱🐍

A Python API for MUD worlds

Python tools for:

  • Querying MUD tables
  • Creating Python game wrappers
  • Interacting with MUD worlds

Use Cases

  • Create data dashboards for MUD worlds
  • Automate in-game actions
  • Build game-specific libraries for player interactions

Installation

pip install mud-aw.py

or build from source

cd mud-aw.py
pip install -e .

Key Components

MUD Indexer SDK

The MUD Indexer SDK provides a simplified interface for querying MUD tables.

Inputs:

  • MUD Indexer URL
  • World Address
  • Path to the mud.config.ts file

fast_compressed_mud_sdk


World Class

The World class allows you to interact with a MUD world and its smart contract functions. It dynamically registers functions based on the ABI, providing type-safe access and auto-completion in your IDE.

Features:

  • Smart Contract Integration: Interact with world contract functions directly.
  • Dynamic Typing: Input arguments and return types are dynamically typed based on the ABI.
  • Integrated Indexer: Optionally link the MUD Indexer for seamless access to table data.

Player Class

The Player class simplifies interactions with a MUD world for a specific player. It can:

  • Derive the player address from a private key
  • Automatically sign and send transactions
  • Dynamically wrap world functions for player-specific interactions

Usage

1. Initialize the World

The World class connects to a MUD world and optionally integrates the MUD Indexer.

from mud import World

abi_dir = "./path/to/abi"
rpc = "https://rpc.mudchain.com"
world_address = "0x123...abc"
indexer_url = "https://indexer.mudchain.com"
mud_config_path = "./path/to/mud.config.ts"

# Initialize the World with an optional indexer
world = World(
    rpc=rpc,
    world_address=world_address,
    abi_dir=abi_dir,
    indexer_url=indexer_url,
    mud_config_path=mud_config_path
)

2. Access Contract Functions

Functions from the world's ABI are dynamically registered on the World instance with type-safe signatures.

# Call a smart contract function directly
land_items = world.getLandItems(user="0x123...")
print(land_items)

# Use IDE auto-completion for arguments and types
world.placeItem(x=1, y=2, z=3, itemId=42)

3. Query Tables with the Indexer

If the world is linked to a MUD Indexer, you can query tables directly.

# Fetch all entries from the Inventory table
inventories = world.indexer.Inventory.get()

# Filter entries by playerId and itemId
player_inventory = world.indexer.Inventory.get(playerId=PLAYER_ID, itemId=ITEM_ID)

# Limit results
limited_inventories = world.indexer.Inventory.get(limit=500)

4. Initialize a Player

The Player class wraps interactions for a specific player.

from mud import Player

private_key = "0xYourPrivateKey"

# Initialize the Player
player = Player(private_key=private_key)

# Link the World to the Player
player.add_world(world, "cafecosmos")

# Call functions directly through the Player
player.cafecosmos.placeItem(x=1, y=1, z=1, itemId=100)

You can also load the private key from an environment variable:

player = Player(env_key_name="PLAYER1")

Features

  • Dynamic Table Registration: Automatically register tables and schemas defined in a MUD configuration file.
  • SQL-like Queries: Query tables with filtering.
  • Smart Contract Interactions: Access world contract functions dynamically.
  • Player-Specific Wrappers: Automate transactions and player actions.

Contributing

  1. Fork the repository.
  2. Create a new feature branch.
  3. Submit a pull request.

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

mud-aw.py-0.1.3.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

mud_aw.py-0.1.3-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file mud-aw.py-0.1.3.tar.gz.

File metadata

  • Download URL: mud-aw.py-0.1.3.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.20

File hashes

Hashes for mud-aw.py-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fe60e76c340796286162e7284f9a3198e14931cfe9983ea4484d4ad0d48b9a2f
MD5 dd4db064b41a7a3aadc1cca3c1cc2a18
BLAKE2b-256 bbcb3734ca89cc00a533785bdc1b3c58d2eb30e13d026455df513c1bb963af6f

See more details on using hashes here.

File details

Details for the file mud_aw.py-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mud_aw.py-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.20

File hashes

Hashes for mud_aw.py-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dc6082ea25a5e19e323d7402641b991ab6026348e7bb5a61f50c1e43dfb9cdcc
MD5 610a28748372594e082c9e161822ba45
BLAKE2b-256 b6367d7b3fd0d78d646be09ced0ac4cc2994755d5fc5de6f6d6af1a880b294b0

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