nbtlib
A python library to read and edit nbt data. Also provides an api to define compound tag schemas in order to save some typing with recurring tag hierarchies. Requires python 3.6.
Installation
The package can be installed with pip.
$ pip install nbtlib
Basic usage
The following examples will give you a very basic overview of what you can do. For more advanced examples, check out the “Usage” notebook in the docs folder.
Reading files
Reading files can be done directly with the load() function. The root property contains the root nbt tag. Every nbt tag inherits from its python counterpart so you can use all the usual builtin operations on nbt tags.
from nbtlib import nbt
nbt_file = nbt.load('bigtest.nbt')
assert nbt_file.root['intTest'] == 2147483647
Editing files
You can use nbt files as context managers in order to save modifications automatically at the end of the with block.
from nbtlib import nbt
from nbtlib.tag import *
with nbt.load('demo.nbt') as demo:
demo.root['counter'] = Int(demo.root['counter'] + 1)
You can also use the save() method.
from nbtlib import nbt
from nbtlib.tag import *
demo = nbt.load('demo.nbt')
demo.root['counter'] = Int(demo.root['counter'] + 1)
demo.save()
For more details check out the “Usage” notebook.
Using schemas
A schema lets you create compound tags that enforce a specific tag type for any given key.
from nbtlib import schema
from nbtlib.tag import *
MySchema = schema('MySchema', {
'foo': String,
'bar': Short
})
my_object = MySchema({'foo': 'hello world', 'bar': 21})
assert isinstance(my_object['foo'], String)
Contributing
Contributions are welcome. Unit tests are built with pytest. You can run the test suite with:
$ python -m pytest tests
License: MIT
Metadata
Release files for nbtlib 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nbtlib-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for nbtlib-0.1.8-py3-none-any.whl |
Release files / nbtlib-0.1.8-py3-none-any.whl
| Download URL | nbtlib-0.1.8-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d77312b9ba8f0a32f27dd9e3ef0f60c3d76c10a30f81226bdbf13c792ff017c
|
|
BLAKE2b-256 checksum How to use checksums |
a7bf781c46936dd2ed831dc25f579511bec61ca1dcb00360edb7840de9bbdc19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for nbtlib 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.