Skip to main content

CI

PyNBT

PyNBT is a tiny, liberally licenced (MIT) NBT library. It supports reading and writing big endian or little endian NBT files. Tested and supported on CPython 3.9-3.14 and PyPy.

Using the Library

Using the library in your own programs is simple and is capable of reading, modifying, and saving NBT files.

Writing

NOTE: Beginning with version 1.1.0, names are optional for TAG_*'s that are added to a TAG_Compound, as they will be given the same name as their key. If you do specify a name, it will be used instead. This breaks compatibility with old code, as the position of the name and value parameter have now swapped.

from pynbt import NBTFile, TAG_Long, TAG_List, TAG_String

value = {
    'long_test': TAG_Long(104005),
    'list_test': TAG_List(TAG_String, [
        'Timmy',
        'Billy',
        'Sally'
    ])
}

nbt = NBTFile(value=value)
with open('out.nbt', 'wb') as io:
  nbt.save(io)

Reading

Reading is simple, and will accept any file-like object providing read(). Simply pretty-printing the file created from the example under writing:

from pynbt import NBTFile

with open('out.nbt', 'rb') as io:
  nbt = NBTFile(io)
  print(nbt.pretty())

This produces the output:

TAG_Compound(''): 2 entries
{
  TAG_Long('long_test'): 104005
  TAG_List('list_test'): 3 entries
  {
    TAG_String(None): 'Timmy'
    TAG_String(None): 'Billy'
    TAG_String(None): 'Sally'
  }
}

Every tag exposes a minimum of two fields, .name and .value. Every tag's value maps to a plain Python type, such as a dict() for TAG_Compound and a list() for TAG_List. Every tag also provides complete __repr__ methods for printing. This makes traversal very simple and familiar to existing Python developers.

with open('out.nbt', 'rb') as io:
  nbt = NBTFile(io)
  # Iterate over every TAG in the root compound as you would any other dict
  for name, tag in nbt.items():
      print(name, tag)

  # Print every tag in a list
  for tag in nbt['list_test']:
      print(tag)

Changelog

These changelogs are summaries only and not comprehensive. See the commit history between tags for full changes.

v3.2.0

  • Pin to mutf8 >= 1.1.0 for decoding/encoding fixes and performance improvements.
  • Modernized tooling, expanded tests up to py3.14.

v3.0.0

  • TAG_Byte_Array now returns and accepts bytearray(), rather than a list of bytes (#18).

v2.0.0

  • Py2 is no longer supported.

v1.4.0

  • Removed pocket detection helpers and RegionFile, leaving PyNBT to only handle NBT.
  • Added a simple unicode test.

v1.3.0

  • Internal cleanups in nbt.py to ease some C work.
  • NBTFile.__init__() and NBTFile.save()'s arguments have changed. For most cases changing compressed=True to NBTFIle.Compression.GZIP will suffice.
  • NBTFile.__init__() and NBTFile.save() no longer accept paths, instead accepting only file-like objects implementing read() and write(), respectively.
  • name must now be provided at construction or before saving of an NBTFile() (defaults to None instead of '').

v1.2.

  • TAG_List's values no longer need to be TAG_* objects. They will be converted when the tag is saved. This allows much easier lists of native types.

v1.2.0

  • Internal code cleanup. Breaks compatibility with pocket loading and saving (to be reimplemented as helpers).
  • Slight speed improvements.
  • TAG_List can now be treated as a plain python list (.value points to self)

v1.1.0

  • Breaks compatibility with older code, but allows much more convenient creation of TAG_Compound. name and value have in most cases swapped spots.
  • name is now the last argument of every TAG_*, and optional for children of a TAG_Compound. Instead, they'll be given the key they're assigned to as a name.
  • TAG_Compounds can now be treated like dictionaries for convienience. .value simply maps to itself.

v1.0.1

  • Small bugfixes.
  • Adds support for TAG_Int_Array.

v1.0.0

  • First release.

Metadata

Release files for PyNBT 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyNBT 3.2.0
File Size Uploaded
pynbt-3.2.0.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyNBT 3.2.0
File Interpreter ABI Platform
pynbt-3.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / pynbt-3.2.0.tar.gz

Download URL pynbt-3.2.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
699f6cac6dcc4adcf391d1a4a23d8e6caa97043cca3532368746decd4fe15eca
BLAKE2b-256 checksum
How to use checksums
c36c51ad4ce7f71299eb5186b18e06465f116229a23a7ac5acc47f442a592885
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 10, 2026.

Transparency log

Release files / pynbt-3.2.0-py3-none-any.whl

Download URL pynbt-3.2.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffbb27c757f90598261ee08d1cc70827d994b2ab902fb941f27ec93f508dc833
BLAKE2b-256 checksum
How to use checksums
45fd40ffae3d92cc332773d706aca38059df2b1bff8e8622663d76dfe52b7c2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.2.0 This release

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.3.2

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page