Skip to main content

A python library for reading and writing NBT files

Project description

Python-NBT

A python library for reading and writing NBT files. Compatible with json.

Based on NBT Version: 19133 (Current version used by Minecraft)

What is NBT

NBT (Named Binary Tag) is a tag based binary format designed to carry large amounts of binary data with smaller amounts of additional data. An NBT file consists of a single GZIPped Named Tag of type TAG_Compound.

From official Minecraft Wiki.

Usage

Read an NBT file

>>> import python_nbt.nbt as nbt
>>> file = nbt.read_from_nbt_file("file.nbt")

This function returns an instance of NBTTagCompound, or by the name on Minecraft Wiki, an instance of TAG_Compound. It only accept 1 argument, which can be either a file path string or an opened file stream.

The TAG_Compound acts like a dict in Python. More accurately, it is a subclass of dict in Python with some restrictions put on its keys and values. So you can get, and set its items as shown below:

>>> file['drop_loot_crates']
{'type_id': 1, 'value': 0}
>>> file['drop_loot_crates'] = nbt.TAG_Byte(1)
>>> file['drop_loot_crates']
{'type_id': 1, 'value': 1}

In the dict shown as above, the key 'type_id' represents the type id of an NBT. In our example, its 'type_id' is 1, which indicates this NBT is a TAG_Byte. And 'value' indicates its actual value.

Write an NBT file

Once you've completed editing an NBT, you can store it into an NBT file with the function below:

write_to_nbt_file(file, tag)

The first argument file should be a path string or a file stream to the file you want to create/write. The second argument tag is the NBT you want to write.

Compat with Json

If you want to export NBT in json, you can use NBTTagBase.json_obj to get an json style dict that contains all the NBT information. After that, you can use json module in Python to do whatever you want.

Note: Unable to import json format into NBT now, this feature is under developing

Future features

  • More json compat
    • Convert json into NBT
    • Better and configurable json output (omitting NBT types)
  • Convinient classes for reading mca files
    • World
    • Region
    • Chunk
  • Convinient classes for mods
    • FTB Quests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Python-NBT-1.0.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

Python_NBT-1.0.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file Python-NBT-1.0.0.tar.gz.

File metadata

  • Download URL: Python-NBT-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.4

File hashes

Hashes for Python-NBT-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2a90b626982a93430ae1d201c099ba61d43d351e11c2c85e4432302453490463
MD5 4d0e13b69165998ff72492518c1d1926
BLAKE2b-256 39991ab53c36663977f204d3b75eba6b654497731beb82dffa0c5f8882441164

See more details on using hashes here.

File details

Details for the file Python_NBT-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: Python_NBT-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.4

File hashes

Hashes for Python_NBT-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43dc8c0365347dcdc81530b43cbf7d13c0e4cac41b1762a17253670b54e6b1fc
MD5 babc51ec5cbeeddb35d3ffd9c122ceb3
BLAKE2b-256 e396fc038974b6ecd443f4adefb78a7bfc62cd935c524f34fabeac204031d00f

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