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.12.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.12-cp38-abi3-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.8+Windows x86-64

nucleation-0.2.12-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.12-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.12-cp38-abi3-macosx_11_0_arm64.whl (5.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

nucleation-0.2.12-cp38-abi3-macosx_10_12_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: nucleation-0.2.12.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.12.tar.gz
Algorithm Hash digest
SHA256 50c42f12558f168a9ac8537a875fcf328a2ad17946a23136899a5d1e9b37b0ae
MD5 c525729b1c333bedb1c46fc24f3fcf64
BLAKE2b-256 b4515496018ad1febd1589901c8acc90c6da287f09dd31654bc44830bc02af3b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nucleation-0.2.12-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.12-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d0ba846f12861853135e95c5ddc621b9fe9a8f027f12be889e2b678a29d368e9
MD5 24439f75719326769772dbec96021cd0
BLAKE2b-256 88bc7e76156b7e5f1808d944321fd234daf3805bb78a48c72d6ddae9d3646863

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nucleation-0.2.12-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5cb5ddb537867294dca90257b970e436fa7abdb9485aeda0970868de8ec1cd5f
MD5 4d40931c3b77fc37d53d63703ff9fca7
BLAKE2b-256 3a3814ed0afcc0356e25bb85aac0467004c807e6c57a7e17b1aeac962354fb5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nucleation-0.2.12-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d064b537659ebc25aabe8b98716c721d42f7498f17dbe64cecc7fac3312bf86d
MD5 950639f668e09235ad427ffdffe80c66
BLAKE2b-256 2d1cd788564c0cd8e1fe0b3d8ca44ed81519a42afb72bc52ee14a87230c5227f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nucleation-0.2.12-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f8ada544cf5e32f7c76c33ceefa5531167783de2eff0c7411d3b9d49889a9aa3
MD5 928b03c3a4ed7b44ba56f1407c153dcf
BLAKE2b-256 14f5e5981b4a6deaebee6bb5c3b32e9d2f68786e56bd20df1ba71900f8807671

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nucleation-0.2.12-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 58cb9ff7027edae2707d504647f9f05cc87dea129a28d2564f70a74995199a5e
MD5 04e780ad9204c9273eb94764b366351a
BLAKE2b-256 462093c42ad791177fc226d50251420d47800758abd6a204b5da2ec8fff4308a

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