Utilities to programatically create MuJoCo XML configuration files
Project description
mjxml
Programmatic, type-checked helpers for composing MuJoCo XML. Define assets and worldbody elements in Python (with Pydantic validation), serialize to XML, and write files you can load in MuJoCo.
Highlights
- Strong typing and validation via Pydantic v2.
- Easy XML serialization:
to_xml(),to_xml_str(),write(). - Assets:
TextureAsset,MeshAsset,HFieldAsset,ModelAsset. - Bodies:
Geom(with many MuJoCo attributes),WorldBodybase. - Utilities:
Defaultsblocks, rotation helpers, and runtime type protocols.
Requirements
- Python >= 3.13
- Runtime deps:
numpy,pydantic
Install
From a checkout of this repository:
pip install -e .
For development (tests and linting):
pip install pytest ruff
If you run examples or tests without installing, set PYTHONPATH to include src.
export PYTHONPATH=src
Quickstart
Below are minimal examples showing how to construct elements and serialize them.
Texture asset
from asset.texture import TextureAsset
tex = TextureAsset(
name="tex_grid",
file="albedo.png",
type="2d",
colorspace="srgb",
content_type="image/png",
nchannel=3,
)
# ElementTree element
elem = tex.to_xml()
# Pretty string
print(tex.to_xml_str())
# Write to a file
tex.write("texture.xml")
Generated <texture> will include only attributes you set and perform validation (e.g., nchannel must be 1, 3, or 4; random in [0,1]).
Mesh asset
from asset.mesh import MeshAsset
mesh = MeshAsset(
name="m_cube",
file="cube.obj",
content_type="model/obj",
scale=[1.0, 1.0, 1.0],
inertia="exact",
)
print(mesh.to_xml_str())
MeshAsset supports inline data (vertex/normal/texcoord/face), reference poses (refpos/refquat), and procedural builtin shapes.
Height field asset
from asset.hfield import HFieldAsset
hfield = HFieldAsset(
name="terrain",
file="height.png",
content_type="image/png",
nrow=256,
ncol=256,
size=[5.0, 5.0, 1.0, 0.0], # required
)
print(hfield.to_xml_str())
size is required and encodes (radius_x, radius_y, elevation_z, base_z).
Geom
from body.geom import Geom
g = Geom(
name="box1",
type="box",
size=[0.5, 0.5, 0.5],
rgba=[0.8, 0.2, 0.2, 1.0],
friction=[0.5, 0.1, 0.01],
)
print(g.to_xml_str())
If friction is provided, condim is emitted as its length, matching MuJoCo’s behavior.
Testing
Run the unit tests with pytest.
pytest -q -s
Status
This repository is under active development; expect minor API adjustments. A high-level MujocoModel aggregator is planned but not yet included.
Roadmap
- [✅] High-level Wrapper:
MujocoModelclass to aggregate assets, worldbody, and other sections. - [✅] Body Elements: Support for
joint,site,camera. - [=] Sections: Support for
actuator,sensor,equality,contact,tendon. - [❌] IO: Parsing existing XML files for round-trip editing.
- [❌] Docs: Comprehensive API documentation and more examples.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mjxml-0.1.0.tar.gz.
File metadata
- Download URL: mjxml-0.1.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f53b3f953d8b173fec7fd70a58377b3e34f17f2e62e7d83778cdc0883cd1e00
|
|
| MD5 |
8928b235bf99d922df987502773fb17b
|
|
| BLAKE2b-256 |
9fc26cc3be685baf5f5efd06b5d2a54a2fc6c530b5a5148f03e177bf8ba402d1
|
File details
Details for the file mjxml-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mjxml-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29746367b5089be12f8ecbc36608e9dd8211fe41242a2de79b5a9c1a31b391fe
|
|
| MD5 |
0f2aa6576a35c145cee10812b991bd6f
|
|
| BLAKE2b-256 |
fa7d7e73dbbd4ec8a5d9a702cd885d3e0da7d326b26b512cb382e05f76826f90
|