DocsCurrent Page

Python SDK


Python tools for DexBotics simulations and testing.


Installation


The TypeScript SDK is the primary SDK. For Python simulations, use the simulation scripts directly from the repository.


bash
git clone https://github.com/dexbotics/market_prod.git
cd market_prod/sims/python

Basic Simulation


The repository includes a simple Python swarm simulator:


python
import random
import time
import json

def simulate():
    agents = [f"robot-{i:02d}" for i in range(5)]
    for t in range(8):
        agent = random.choice(agents)
        evt = {
            "t": t,
            "assignee": agent,
            "proof_hash": "0x" + "07" * 32
        }
        print(json.dumps(evt))
        time.sleep(0.05)

if __name__ == "__main__":
    simulate()

Running the Simulator


bash
cd sims/python
python swarm.py

This will output simulated agent events showing task assignments and proof submissions.


Custom Simulations


You can extend the simulation by:


1. Adding more agents: Modify the agents list to include more robots

2. Task complexity: Add additional event types and task states

3. Integration with SDK: Use the TypeScript SDK via subprocess calls to interact with real on-chain data


Multi-Agent Simulation


Example of a more complex simulation with task coordination:


python
import random
import time
import json

class SimulatedAgent:
    def __init__(self, agent_id):
        self.agent_id = agent_id
        self.tasks_completed = 0

    def accept_task(self, task_id):
        return {
            "event": "task_accepted",
            "agent": self.agent_id,
            "task_id": task_id,
            "timestamp": time.time()
        }

    def submit_proof(self, task_id):
        self.tasks_completed += 1
        return {
            "event": "proof_submitted",
            "agent": self.agent_id,
            "task_id": task_id,
            "proof_hash": "0x" + "07" * 32,
            "timestamp": time.time()
        }

def run_swarm(num_agents=10, num_tasks=20):
    agents = [SimulatedAgent(f"robot-{i:02d}") for i in range(num_agents)]

    for task_id in range(num_tasks):
        agent = random.choice(agents)

        accept_evt = agent.accept_task(task_id)
        print(json.dumps(accept_evt))
        time.sleep(0.1)

        proof_evt = agent.submit_proof(task_id)
        print(json.dumps(proof_evt))
        time.sleep(0.1)

    print("\nSimulation complete:")
    for agent in agents:
        print(f"{agent.agent_id}: {agent.tasks_completed} tasks")

if __name__ == "__main__":
    run_swarm(num_agents=10, num_tasks=20)

Integration with On-Chain Data


For production simulations that interact with the actual Solana program, use the TypeScript SDK:


python
import subprocess
import json

def create_task_via_sdk():
    result = subprocess.run([
        "npx", "ts-node", "../sdk/ts/examples/devnet-demo.ts"
    ], capture_output=True, text=True)

    return result.stdout

task_pubkey = create_task_via_sdk()
print(f"Created task: {task_pubkey}")