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.
Installation
pip install Python-NBT
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(full_json=True) 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.
If you want a simpler version, which omits type id of an NBT and NBTs inside it, set full_json to False.
Note: Changing full_json to False will also turn json dict of nested tags into simple version.
If you want to import NBT from a json object, you can use nbt.from_json(json_obj) to do so.
This function will return an NBT object. And its argument must be as same format as what NBTTagBase.json_obj(full_json=True) exports.
Future features
Ticked entries are finished.
- More json compat
- Convert json into NBT
- Better and configurable json output (omitting NBT types)
- Convenient classes for reading and writing Minecraft saves files
- World
- Region
- Chunk
- ItemStack
- TileEntity
- Entity
- Player
- Utilities for mods
- FTB Quests (CurseForge Link)
- GameStages (CurseForge Link)
- Recognize blocks and items form mods in World according to NEI exports
- A detailed ~~doc/~~wiki
- More convenient interfaces for NBT (try to fully abandon
valueproperty, and makes everthing just it should be)- Operators for numeric tags
- +, -, *, /
- **, //
- >, <
- List interfaces for array-like NBT
- Dict interfaces for dict-like NBT
- Operators for numeric tags
Release files for Python-NBT 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| Python-NBT-1.2.0.tar.gz | 8.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Python_NBT-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.2 kB
Release files / Python-NBT-1.2.0.tar.gz
| Download URL | Python-NBT-1.2.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97785f1c029529836c10d1d4b171b0368ac69a8eebce27a660b081c7801bf5e2
|
|
BLAKE2b-256 checksum How to use checksums |
fd68d8d732d3b4ee27c270f29e6d458dc1900e39cb0788a0f415b4fada38bf2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / Python_NBT-1.2.0-py3-none-any.whl
| Download URL | Python_NBT-1.2.0-py3-none-any.whl |
|---|---|
| Size | 21.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a2377bc4ede916635ea68678f31af4f3cabf9ada33fe16d5129b72df9ddff17
|
|
BLAKE2b-256 checksum How to use checksums |
3d8394efc58158c7e67c8f9e261d7e3264ebf806145348bb28d5ed0d8aaebc7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|