Skip to main content

A high-performance Minecraft schematic parser and utility library

Project description

Nucleation for Python

PyPI

Python bindings for Nucleation, a high-performance Minecraft schematic engine. Read, edit, build, simulate, and mesh .schematic, .litematic, .nbt, and .mcstructure files — at native speed.

The core is written in Rust and compiled to a CPython extension via PyO3 (abi3-py38), so a single wheel works on every CPython 3.8+ on your platform — no Rust toolchain required to install.


Install

pip install nucleation

Pre-built wheels are published for:

  • Linux x86_64 and aarch64
  • macOS x86_64 (Intel) and arm64 (Apple Silicon)
  • Windows x86_64

If your platform isn't covered, pip will fall back to the source distribution and build locally (requires a Rust toolchain).


Quick start

from nucleation import Schematic, sign, text

# Three explicit constructors (legacy `Schematic("file.schem")` still works):
schem = Schematic.open("example.litematic")        # load from disk
fresh = Schematic.new("my_schematic")              # blank
templ = Schematic.from_template("ab\ncd")          # ASCII template

# Polished set_block: tuple coords, structured state and NBT, chainable.
schem.set_block((0, 0, 0), "minecraft:repeater",
                state={"delay": 4, "facing": "east"})
schem.set_block((0, 1, 0), "minecraft:oak_sign",
                state={"rotation": 8},
                nbt=sign([text("Hello", color="gold"), "world"]))

# Format inferred from extension.
schem.save("out.litematic")

Hot loops

For placing many blocks, prefer the batch and fast-path APIs:

# 30+ M placements/sec — one native call.
schem.set_blocks([(x, 0, 0) for x in range(1_000_000)], "minecraft:stone")

# 10+ M placements/sec — pre-resolve once, place by index.
stone = schem.prepare_block("minecraft:stone")
place = schem.place
for x, y, z in positions:
    place(x, y, z, stone)

Tile-entity helpers

from nucleation import Schematic, chest, sign, text, Item

schem = Schematic.new("loot_room")

schem.set_block((0, 0, 0), "minecraft:chest",
                state={"facing": "north"},
                nbt=chest([
                    Item("minecraft:diamond", count=64),
                    Item("minecraft:elytra"),
                ]))

schem.set_block((0, 1, 0), "minecraft:oak_sign",
                nbt=sign([text("Loot", color="gold"), "this way →"]))

Remote storage

Schematic.open and schem.save work transparently against remote backends — no extra object, no manual byte-shuffling. The same calls you use for local files take a scheme'd URI or an explicit Store:

from nucleation import Schematic, Store

# local file (unchanged)
schem = Schematic.open("build.schem")
schem.save("build.litematic")

# transparent remote: a scheme'd URI, no Store object needed
schem = Schematic.open("s3://my-bucket/builds/adder.schem")
schem.save("s3://my-bucket/out/adder.schem")
schem.save("file:///tmp/adder.litematic")   # file:// = local path

# explicit Store + key: works for ANY backend (incl. redis/postgres)
# and reuses a single connection
store = Store.open("redis://localhost:6379")
schem = Schematic.open(store, "builds/adder.schem")
schem.save(store, "out/adder.schem")

The format is inferred from the key/path extension (.schem, .litematic, .mcstructure); pass format="litematic" etc. to save to override it.

The single-string form works for path-like backends — s3://bucket/key (and file:// → local). redis:// and postgres:// single-strings raise ValueError, because their URL path is the database, leaving no slot for the key; open those with an explicit store instead: Schematic.open(Store.open(url), key).

Which backends are reachable depends on the store-* features the extension was built with. The default wheel ships mem:// + file://; for S3/Redis/Postgres rebuild it:

maturin develop --features python,store-s3,store-redis,store-pg

Raw byte store. When you want raw bytes rather than schematics — PNG renders, arbitrary artifacts — use the Store class directly (get/put/exists/delete/list/health).


Diff & Fingerprint

Canonically fingerprint a build, dedup near-duplicates, and compute a structural diff between two builds — all under a configurable equivalence ruleset chosen by preset name:

  • exact — material- and orientation-sensitive (identical blockstates only).
  • shape — occupancy only; palette and orientation ignored.
  • structural — functional shape, rotation- and material-agnostic.
  • redstone_computational (alias redstone) — redstone-logic equivalence, rotation-agnostic, cosmetic-material-agnostic.
  • redstone_survival — like redstone, but keeps survival material constraints.

diff additionally accepts opt-in overrides: per-edit cost weights (cost_add / cost_delete / cost_change / cost_swap) and a symmetry group.

from nucleation import Schematic

a = Schematic.open("a.litematic")
b = Schematic.open("b.litematic")

# 32-hex canonical hash (rotation/translation/palette-agnostic per preset).
print(a.fingerprint("structural"))

# Cheap exact-equivalence dedup, and fuzzy FFT shape distance (0.0 == same shape).
if a.is_duplicate_of(b, "structural"):
    print("duplicate build")
print("footprint distance:", a.footprint_distance(b, "structural"))

# Dims + token histogram as JSON.
print(a.signature("structural"))

# Structural diff (optionally pass cost_*/symmetry overrides).
d = a.diff(b, "redstone")
print("distance:", d.distance())
# support = fraction of the larger build's cells that aligned (confidence,
# NOT a similarity %).
print("support:", d.support())

# Each delta as its own Schematic.
d.added(); d.removed(); d.changed(); d.swapped(); d.markers()

# Lossless JSON round-trips via Diff.from_json; summary_json() is compact.
from nucleation import Diff
full = d.to_json()
restored = Diff.from_json(full)
print(d.summary_json())

The glowing-overlay GLB requires the meshing feature in your wheel:

# `after_glb` is the meshed "after" build (bytes); returns a new GLB.
glb = d.to_overlay_glb(after_glb)
with open("diff_overlay.glb", "wb") as f:
    f.write(glb)

Documentation

Full reference, including simulation, meshing, and resource-pack rendering, lives in the main repository:


Why Rust?

Nucleation's core is shared across Rust, WebAssembly/JS, Python, and C/PHP — one engine, one set of behaviour, one set of tests. The Python package you install is the same engine that powers the JS and Rust libraries; you get native throughput for free.

License

AGPL-3.0-only. See the main repository for details.

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

nucleation-0.2.13.tar.gz (5.1 MB view details)

Uploaded Source

Built Distributions

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

nucleation-0.2.13-cp38-abi3-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.8+Windows x86-64

nucleation-0.2.13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

nucleation-0.2.13-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

nucleation-0.2.13-cp38-abi3-macosx_11_0_arm64.whl (5.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

nucleation-0.2.13-cp38-abi3-macosx_10_12_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file nucleation-0.2.13.tar.gz.

File metadata

  • Download URL: nucleation-0.2.13.tar.gz
  • Upload date:
  • Size: 5.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for nucleation-0.2.13.tar.gz
Algorithm Hash digest
SHA256 e162ce634b78f6e3c2d27d5fc416237ea763a5513ec1ddcd2d9673ae9f2f5c5d
MD5 91f06689da76bfd52aff0821687a5a24
BLAKE2b-256 20d767b13e87af1d1f1201323359c5ff07ad8140dae46b4b4cb17a0a77ea8d8b

See more details on using hashes here.

File details

Details for the file nucleation-0.2.13-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: nucleation-0.2.13-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.0 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for nucleation-0.2.13-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3c54f1a1a820e2f06291d025c9b871cbf3a38f7ab310a58f93348f5ff9efccab
MD5 9f6a26f14b1a4bf0e6c39c63ae82cef1
BLAKE2b-256 23791a384cbb3f0dd9e4c9167f70f482a53e3539049412bed922df185088920a

See more details on using hashes here.

File details

Details for the file nucleation-0.2.13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nucleation-0.2.13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d20368c9d85623cc7575c04ee26fb1bc740716b01424c59e086b31a90a904d48
MD5 fc2c5a9872e29f15e48fba20155da6d3
BLAKE2b-256 32b89537f7d2680c23b1d1e24ce7701d09329d70bbb65f7fbcfe757bcc051bc5

See more details on using hashes here.

File details

Details for the file nucleation-0.2.13-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nucleation-0.2.13-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cc5b09a49b71a42a8ea35e884390dce396b882814d101a7275912e2bd0845433
MD5 c1007b4000c736b061e816072b69ee97
BLAKE2b-256 c47bd68c10f1fec44a612c4f0780b5f1d322208c42ca3dd9c5ab08a822860e2f

See more details on using hashes here.

File details

Details for the file nucleation-0.2.13-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nucleation-0.2.13-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 61d27ca87652bd97f1ea3ba7b8acc50c4d81467bfab3118a3f9390d7c02c6c44
MD5 71adf7802ba7ffd50b85bb29f0e08ac3
BLAKE2b-256 c64be6d2a5ea212152d75f1e9da7a201bd8ceb24a3573351f73a8149e5059d61

See more details on using hashes here.

File details

Details for the file nucleation-0.2.13-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nucleation-0.2.13-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ca4b9a1b396164e679a2f5a0b30bd6aac8448f45ebe9f62fca68fb3b23b8a4fc
MD5 98992ef0b9370f379685fdcb33f1865b
BLAKE2b-256 8251d2b5ddc96d778c023c98dad0ce7e93acd459710d463a48d5520772067fec

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