Name | NBT JSON |
Version |
1.5.1
JSON |
| download |
home_page | http://github.com/twoolie/NBT |
Summary | Named Binary Tag Reader/Writer |
upload_time | 2021-12-22 15:48:31 |
maintainer | |
docs_url | None |
author | Thomas Woolford |
requires_python | |
license | Copyright (c) 2010-2013 Thomas Woolford and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
|
coveralls test coverage |
No coveralls.
|
==========================
The NBT library for Python
==========================
Forewords
=========
This is mainly a `Named Binary Tag` parser & writer library.
From the initial specification by Markus Persson::
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.
Current specification is on the official [Minecraft Wiki](https://minecraft.gamepedia.com/NBT_format).
This library is very suited to inspect & edit the Minecraft data files. Provided
examples demonstrate how to:
- get player and world statistics,
- list mobs, chest contents, biomes,
- draw a simple world map,
- etc.
.. image:: world.png
*Note: Examples are just here to help using and testing the library.
Developing Minecraft tools is out of the scope of this project.*
Status
======
The library supports all the currently known tag types (including the arrays
of 'Integer' and 'Long'), and the examples work with the McRegion,
pre-"flattened" and "flattened" Anvil formats.
Last update was tested on Minecraft version **1.13.2**.
Dependencies
============
The library, the tests and the examples are only using the Python core library,
except `curl` for downloading some test reference data and `PIL` (Python
Imaging Library) for the `map` example.
Supported Python releases: 2.7, 3.4 to 3.7
Usage
=====
Reading files
-------------
The easiest way to read an nbt file is to instantiate an NBTFile object e.g.::
>>> from nbt import nbt
>>> nbtfile = nbt.NBTFile("bigtest.nbt",'rb')
>>> nbtfile.name
u'Level'
>>> nbtfile["nested compound test"].tag_info()
TAG_Compound("nested compound test"): 2 Entries
>>> for tag in nbtfile["nested compound test"]["ham"].tags:
... print(tag.tag_info())
...
TAG_String("name"): Hampus
TAG_Float("value"): 0.75
>>> [tag.value for tag in nbtfile["listTest (long)"].value]
[11, 12, 13, 14, 15]
Files can also be read from a fileobj (file-like object that contains a compressed
stream) or a buffer (file-like object that contains an uncompressed stream of NBT
Tags) which can be accomplished thusly::
>>> from nbt.nbt import *
>>> nbtfile = NBTFile(fileobj=previously_opened_file)
# or....
>>> nbtfile = NBTFile(buffer=net_socket.makefile())
Writing files
-------------
Writing files is easy too! if you have a NBTFile object, simply call it's
write_file() method. If the NBTFile was instantiated with a filename, then
write_file needs no extra arguments. It just works. If however you created a new
file object from scratch (or even if you just want to save it somewhere else)
call write_file('path\to\new\file.nbt')::
>>> from nbt import nbt
>>> nbtfile = nbt.NBTFile("bigtest.nbt",'rb')
>>> nbtfile["listTest (compound)"].tags[0]["name"].value = "Different name"
>>> nbtfile.write_file("newnbtfile.nbt")
It is also possible to write to a buffer or fileobj using the same keyword args::
>>> nbtfile.write_file(fileobj = my_file) #compressed
>>> nbtfile.write_file(buffer = sock.makefile()) #uncompressed
Creating files
--------------
Creating files is trickier but ultimately should give you no issue, as long as
you have read the NBT spec (hint.. it's very short). Also be sure to note that
the NBTFile object is actually a TAG_Compound with some wrapper features, so
you can use all the standard tag features::
>>> from nbt.nbt import *
>>> nbtfile = NBTFile()
First, don't forget to name the top level tag::
>>> nbtfile.name = "My Top Level Tag"
>>> nbtfile.tags.append(TAG_Float(name="My Float Name", value=3.152987593947))
>>> mylist = TAG_List(name="TestList", type=TAG_Long) #type needs to be pre-declared!
>>> mylist.tags.append(TAG_Long(100))
>>> mylist.tags.extend([TAG_Long(120),TAG_Long(320),TAG_Long(19)])
>>> nbtfile.tags.append(mylist)
>>> print(nbtfile.pretty_tree())
TAG_Compound("My Top Level Tag"): 2 Entries
{
TAG_Float("My Float Name"): 3.15298759395
TAG_List("TestList"): 4 entries of type TAG_Long
{
TAG_Long: 100
TAG_Long: 120
TAG_Long: 320
TAG_Long: 19
}
}
>>> nbtfile["TestList"].tags.sort(key = lambda tag: tag.value)
>>> print(nbtfile.pretty_tree())
TAG_Compound("My Top Level Tag"): 2 Entries
{
TAG_Float("My FloatName"): 3.15298759395
TAG_List("TestList"): 4 entries of type TAG_Long
{
TAG_Long: 19
TAG_Long: 100
TAG_Long: 120
TAG_Long: 320
}
}
>>> nbtfile.write_file("mynbt.dat")
Raw data
{
"_id": null,
"home_page": "http://github.com/twoolie/NBT",
"name": "NBT",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Thomas Woolford",
"author_email": "woolford.thomas@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7a/89/b45d1a3608d0335f0cb6f715dc0363a976981c6b94625de9f4d95417e1b4/NBT-1.5.1.tar.gz",
"platform": "",
"description": "==========================\nThe NBT library for Python\n==========================\n\nForewords\n=========\n\nThis is mainly a `Named Binary Tag` parser & writer library.\n\nFrom the initial specification by Markus Persson::\n\n NBT (Named Binary Tag) is a tag based binary format designed to carry large\n amounts of binary data with smaller amounts of additional data.\n An NBT file consists of a single GZIPped Named Tag of type TAG_Compound.\n\nCurrent specification is on the official [Minecraft Wiki](https://minecraft.gamepedia.com/NBT_format).\n\nThis library is very suited to inspect & edit the Minecraft data files. Provided\nexamples demonstrate how to:\n- get player and world statistics,\n- list mobs, chest contents, biomes,\n- draw a simple world map,\n- etc.\n\n.. image:: world.png\n\n*Note: Examples are just here to help using and testing the library.\nDeveloping Minecraft tools is out of the scope of this project.*\n\n\nStatus\n======\n\nThe library supports all the currently known tag types (including the arrays\nof 'Integer' and 'Long'), and the examples work with the McRegion,\npre-\"flattened\" and \"flattened\" Anvil formats.\n\nLast update was tested on Minecraft version **1.13.2**.\n\n\nDependencies\n============\n\nThe library, the tests and the examples are only using the Python core library,\nexcept `curl` for downloading some test reference data and `PIL` (Python\nImaging Library) for the `map` example.\n\nSupported Python releases: 2.7, 3.4 to 3.7\n\n\nUsage\n=====\n\nReading files\n-------------\n\nThe easiest way to read an nbt file is to instantiate an NBTFile object e.g.::\n\n >>> from nbt import nbt\n >>> nbtfile = nbt.NBTFile(\"bigtest.nbt\",'rb')\n >>> nbtfile.name\n u'Level'\n >>> nbtfile[\"nested compound test\"].tag_info()\n TAG_Compound(\"nested compound test\"): 2 Entries\n >>> for tag in nbtfile[\"nested compound test\"][\"ham\"].tags:\n ... print(tag.tag_info())\n ...\n TAG_String(\"name\"): Hampus\n TAG_Float(\"value\"): 0.75\n >>> [tag.value for tag in nbtfile[\"listTest (long)\"].value]\n [11, 12, 13, 14, 15]\n\nFiles can also be read from a fileobj (file-like object that contains a compressed\nstream) or a buffer (file-like object that contains an uncompressed stream of NBT\nTags) which can be accomplished thusly::\n\n >>> from nbt.nbt import *\n >>> nbtfile = NBTFile(fileobj=previously_opened_file)\n # or....\n >>> nbtfile = NBTFile(buffer=net_socket.makefile())\n\n\nWriting files\n-------------\n\nWriting files is easy too! if you have a NBTFile object, simply call it's\nwrite_file() method. If the NBTFile was instantiated with a filename, then\nwrite_file needs no extra arguments. It just works. If however you created a new\nfile object from scratch (or even if you just want to save it somewhere else)\ncall write_file('path\\to\\new\\file.nbt')::\n\n >>> from nbt import nbt\n >>> nbtfile = nbt.NBTFile(\"bigtest.nbt\",'rb')\n >>> nbtfile[\"listTest (compound)\"].tags[0][\"name\"].value = \"Different name\"\n >>> nbtfile.write_file(\"newnbtfile.nbt\")\n\nIt is also possible to write to a buffer or fileobj using the same keyword args::\n\n >>> nbtfile.write_file(fileobj = my_file) #compressed\n >>> nbtfile.write_file(buffer = sock.makefile()) #uncompressed\n\n\nCreating files\n--------------\n\nCreating files is trickier but ultimately should give you no issue, as long as\nyou have read the NBT spec (hint.. it's very short). Also be sure to note that\nthe NBTFile object is actually a TAG_Compound with some wrapper features, so\nyou can use all the standard tag features::\n\n >>> from nbt.nbt import *\n >>> nbtfile = NBTFile()\n\n\nFirst, don't forget to name the top level tag::\n\n >>> nbtfile.name = \"My Top Level Tag\"\n >>> nbtfile.tags.append(TAG_Float(name=\"My Float Name\", value=3.152987593947))\n >>> mylist = TAG_List(name=\"TestList\", type=TAG_Long) #type needs to be pre-declared!\n >>> mylist.tags.append(TAG_Long(100))\n >>> mylist.tags.extend([TAG_Long(120),TAG_Long(320),TAG_Long(19)])\n >>> nbtfile.tags.append(mylist)\n >>> print(nbtfile.pretty_tree())\n TAG_Compound(\"My Top Level Tag\"): 2 Entries\n {\n TAG_Float(\"My Float Name\"): 3.15298759395\n TAG_List(\"TestList\"): 4 entries of type TAG_Long\n {\n TAG_Long: 100\n TAG_Long: 120\n TAG_Long: 320\n TAG_Long: 19\n }\n }\n >>> nbtfile[\"TestList\"].tags.sort(key = lambda tag: tag.value)\n >>> print(nbtfile.pretty_tree())\n TAG_Compound(\"My Top Level Tag\"): 2 Entries\n {\n TAG_Float(\"My FloatName\"): 3.15298759395\n TAG_List(\"TestList\"): 4 entries of type TAG_Long\n {\n TAG_Long: 19\n TAG_Long: 100\n TAG_Long: 120\n TAG_Long: 320\n }\n }\n >>> nbtfile.write_file(\"mynbt.dat\")\n\n\n",
"bugtrack_url": null,
"license": "Copyright (c) 2010-2013 Thomas Woolford and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Named Binary Tag Reader/Writer",
"version": "1.5.1",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b9aef3bdbbaccaca97a2bfdd87466a08717a2174f136e3b99a189d32d03d6526",
"md5": "dc4fc7f548e0315db9c848cce7d5e642",
"sha256": "1503314d0374b983642f9f219890330ce19d9d85966a28bdb6bef1fb17c4c2c0"
},
"downloads": -1,
"filename": "NBT-1.5.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "dc4fc7f548e0315db9c848cce7d5e642",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 25601,
"upload_time": "2021-12-22T15:46:34",
"upload_time_iso_8601": "2021-12-22T15:46:34.546807Z",
"url": "https://files.pythonhosted.org/packages/b9/ae/f3bdbbaccaca97a2bfdd87466a08717a2174f136e3b99a189d32d03d6526/NBT-1.5.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7a89b45d1a3608d0335f0cb6f715dc0363a976981c6b94625de9f4d95417e1b4",
"md5": "d579b6be136257d1d5f9a03516ab6a76",
"sha256": "da3bb2137605cb9dfe7446f13f19b3ae7faf920d430a387fb78efde27f6636c5"
},
"downloads": -1,
"filename": "NBT-1.5.1.tar.gz",
"has_sig": false,
"md5_digest": "d579b6be136257d1d5f9a03516ab6a76",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 122703,
"upload_time": "2021-12-22T15:48:31",
"upload_time_iso_8601": "2021-12-22T15:48:31.703499Z",
"url": "https://files.pythonhosted.org/packages/7a/89/b45d1a3608d0335f0cb6f715dc0363a976981c6b94625de9f4d95417e1b4/NBT-1.5.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-12-22 15:48:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "twoolie",
"github_project": "NBT",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"lcname": "nbt"
}