Skip to main content

[!CAUTION] This is a heavily WIP project

RimWorld XML library

This library is designed to assist with writing mods and mod patches for RimWorld. It provides functionality to load game data into an xml file and apply patches to it.

Basic usage

The package provides a convenience function load_world for when you just need to load the rimworld's xml data, apply patches, and then explore the resulting xml as you like.

from pathlib import Path

from rimworld import load_world

# First let's prepare some paths (i'm using wsl2):
RIMWORLD_CORE_PACKAGES = Path("/mnt/e/steam/steamapps/common/RimWorld/Data")
RIMWORLD_LOCAL_MODS = Path("/mnt/e/steam/steamapps/common/Rimworld/Mods")
RIMWORLD_STEAM_MODS = Path("/mnt/e/steam/steamapps/workshop/content/294100")
RIMWORLD_MODSCONFIG_FOLDER = Path(
    "/mnt/c/Users/lai/AppData/LocalLow/Ludeon Studios/"
    "RimWorld by Ludeon Studios/Config/ModsConfig.xml"
)

world = load_world(
    mod_folders=[RIMWORLD_CORE_PACKAGES, RIMWORLD_LOCAL_MODS, RIMWORLD_STEAM_MODS],
    modsconfig_folder=RIMWORLD_MODSCONFIG_FOLDER,
)

print(world.xpath("/Defs/ThingDef/label/text()"))

Slightly more advanced usage

If you need something more advanced, you can go lower level.

Here is basically what load_world from the above example does:

from pathlib import Path

from lxml import etree

from rimworld.mod import ModsConfig, load_mods, select_mods
from rimworld.patch import PatchContext, get_operation
from rimworld.xml import load_xml, merge

# First let's prepare some paths (i'm using wsl2):
RIMWORLD_CORE_PACKAGES = Path("/mnt/e/steam/steamapps/common/RimWorld/Data")
RIMWORLD_LOCAL_MODS = Path("/mnt/e/steam/steamapps/common/Rimworld/Mods")
RIMWORLD_STEAM_MODS = Path("/mnt/e/steam/steamapps/workshop/content/294100")
RIMWORLD_MODSCONFIG_FOLDER = Path(
    "/mnt/c/Users/lai/AppData/LocalLow/Ludeon Studios/"
    "RimWorld by Ludeon Studios/Config/ModsConfig.xml"
)

# We know where our mods are, but we need to load information about them
# This will take a few seconds as the script loads About.xml files
mods_collection = list(
    load_mods(RIMWORLD_CORE_PACKAGES, RIMWORLD_LOCAL_MODS, RIMWORLD_STEAM_MODS)
)

# Now let's load game version, known expansions, and a list of active mods
mods_config = ModsConfig.load(RIMWORLD_MODSCONFIG_FOLDER)

# Select mods from our mods collection which are active
active_mods = list(select_mods(mods_collection, package_id_in=mods_config.active_mods))

# Prepare patching context - this is needed for proper patching
patch_context = PatchContext(
    active_package_ids={m.package_id for m in active_mods},
    active_package_names={m.about.name for m in active_mods if m.about.name},
)

# Create an empty xml tree
tree = etree.ElementTree(etree.Element("Defs"))

# And the final step
for mod in active_mods:
    for def_file in mod.def_files(mods_config):
        merge(tree, load_xml(def_file))
    for patch_file in mod.patch_files(mods_config):
        patch_operation_nodes = load_xml(patch_file).getroot().findall("Operation")
        for patch_operation_node in patch_operation_nodes:
            patch_operation = get_operation(patch_operation_node)
            patch_operation(tree, patch_context)

Metadata

Release files for rimworld 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rimworld 0.3.3
File Size Uploaded
rimworld-0.3.3.tar.gz 21.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rimworld 0.3.3
File Interpreter ABI Platform
rimworld-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 55.6 kB

Release files / rimworld-0.3.3.tar.gz

Download URL rimworld-0.3.3.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
37d0b09ee4beec3b5cc08fd508a9444f503054337336f25e5b025c514dc55b79
BLAKE2b-256 checksum
How to use checksums
2b068f024f2f95b1abb3b4d9ced2fb204bc0138d92e8839e74ac7710526a2b7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/5.15.153.1-microsoft-standard-WSL2

Release files / rimworld-0.3.3-py3-none-any.whl

Download URL rimworld-0.3.3-py3-none-any.whl
Size 33.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7dc6b7c2066266d91c4e0e4890b64b7c504b037895dd3159f856893df7070eea
BLAKE2b-256 checksum
How to use checksums
b6b5d0877f6c37d408ae996f004a9de96028565ea7b28a2f3e7d06b171992d04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/5.15.153.1-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page