keyvalues3
KeyValues3 is a Valve developed data format. It is similar in structure to JSON, but supports binary encodings, versioning, and data annotations. The text syntax also has some minor ergonomic improvements (support for single- and multi-line comments, trailing commas, and multi-line strings.)
Usage
import keyvalues3 as kv3
bt_config = kv3.read("tests/documents/bt_config.kv3")
>>> bt_config.keys()
dict_keys(['default', 'low', 'fair', 'normal', 'tough', 'hard', 'very_hard', 'expert', 'elite'])
>>> bt_config["elite"]["reaction_time"]
0.12
# The root value is most of the time a dict
>>> type(bt_config.value)
<class 'dict'>
>>> bt_config.original_encoding
Encoding(name='text', version=UUID('e21c7f3c-8a33-41c5-9977-a76d3a32aa0d'))
>>> bt_config.format
Format(name='generic', version=UUID('7412167c-06e9-4698-aff2-e63eb59037e7'))
# To write it back
>>> kv3.write(bt_config, "tests/documents/bt_config.kv3", use_original_encoding=True)
# Write to a stream
>>> import sys
>>> kv3.write({"key": [1,2,3]}, sys.stdout)
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
{
key = [1, 2, 3]
}
Install 
pip install keyvalues3
Supported encodings
| Encoding 👩💻 | Read 📖 | Write ✍️ |
|---|---|---|
| Text UTF-8 | Yes ✔️ | Yes ✔️ |
| Text UTF-8 Headerless | Yes ✔️ | Yes ✔️ |
| Binary (VKV) Uncompressed | Yes ✔️ | Yes ✔️ |
| Binary (VKV) LZ4 | Yes ✔️ | Yes ✔️ |
| Binary (3VK) V1 | Yes ✔️ | No ⛔ |
| Binary (3VK) V2 | Yes ✔️ | No ⛔ |
| Binary (3VK) V3 | Yes ✔️ | No ⛔ |
| Binary (3VK) V4 | Yes ✔️ | No ⛔ |
| Binary (3VK) V5 | Yes ✔️ | No ⛔ |
Using dataclasses
Dataclasses (marked with @dataclass) are also supported for serialization (uses asdict())
@dataclass
class RenderMeshFile(_Node): # _Node defines _class, name, notes, and children (+ helper methods)
filename: resourcepath = ""
import_translation: list[float] = field(default_factory=lambda: [0, 0, 0])
import_rotation: list[float] = field(default_factory=lambda: [0, 0, 0])
import_scale: float = 1.0
align_origin_x_type: str = "None"
align_origin_y_type: str = "None"
align_origin_z_type: str = "None"
parent_bone: namelink = ""
import_filter: dict = field(
default_factory=lambda:dict(
exclude_by_default = False,
exception_list = [ ]
)
)
You can find more ModelDoc dataclasses here.
Developing
python --version Ensure you're using Python 3.12 or greater.
python -m pip install .
python -m pip install pytest I don't know why this is needed
python -m pytest
Credits
Valve Corporation® for making KeyValues3.
ValveResourceFormat for the legacy binary reader reference.
SourceIO by REDxEYE for new binary reader code.
Metadata
Release files for keyvalues3 0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keyvalues3-0.7.tar.gz | 122.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keyvalues3-0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 145.7 kB
Release files / keyvalues3-0.7.tar.gz
| Download URL | keyvalues3-0.7.tar.gz |
|---|---|
| Size | 122.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1dfbd6c46b7a815fc5a6c749e1a680b7148edb8e7c8c18a4b98ee394f43e91b
|
|
BLAKE2b-256 checksum How to use checksums |
8fa686913066d1a994fefb51bbac703d3e1d02d9339c5450e3eb359fa7d41ead
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.34.2
|
Release files / keyvalues3-0.7-py3-none-any.whl
| Download URL | keyvalues3-0.7-py3-none-any.whl |
|---|---|
| Size | 23.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
56d6e49ab76244f56eda10c2fc454dc6d67a2647122961c5ee1ecd709f1076b9
|
|
BLAKE2b-256 checksum How to use checksums |
b2f968b09b36596c99e51b3aa35539df5dcc24c57552dee63bf6c0def8865b0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.34.2
|