| Name | kv3parser JSON |
| Version |
1.1
JSON |
| download |
| home_page | None |
| Summary | A parser for KV3 file format |
| upload_time | 2024-08-28 04:16:57 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.6 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# kv3parser
A Python parser for converting KV3 (KeyValues3) data format to JSON, built for data analysis in the game Deadlock.
## Installation
You can install kv3parser using pip:
```
pip install kv3parser
```
## Overview
This project provides a robust parser that can read KV3 formatted data from .vdata files and convert it to JSON. KV3 is a data format used in some Valve games and tools, including Deadlock. By converting KV3 to JSON, this parser facilitates easier analysis and manipulation of game data using standard JSON tools and libraries.
## Features
- Parses KV3 formatted data from .vdata files and converts it to JSON
- Handles complex KV3 structures including nested objects and arrays
- Supports various data types: strings, numbers, booleans, null values
- Recognizes and preserves KV3-specific flags (resource, resourcename, panorama, soundevent, subclass)
- Provides detailed error messages with line and column information for parsing errors
- Supports multi-line strings
- Handles comments (both single-line and multi-line)
- Allows for flexible syntax, such as omitting commas between key-value pairs
## Usage
```python
import json
from kv3parser import kv3_to_json
# Path to your .vdata file
vdata_file_path = 'path/to/your/file.vdata'
# Read the content of the .vdata file
with open(vdata_file_path, 'r', encoding='utf-8') as file:
vdata_content = file.read()
try:
# Parse the KV3 content
json_output = kv3_to_json(vdata_content)
# Print or save the JSON output
print(json_output)
# Optionally, save to a file
with open('output.json', 'w', encoding='utf-8') as json_file:
json_file.write(json_output)
except Exception as e:
print(f"Error parsing KV3: {e}")
```
This script does the following:
1. Reads a .vdata file (which uses the KV3 format).
2. Parses the content using `kv3_to_json()`.
3. Saves the resulting JSON to a file.
4. Provides an example of how to load the JSON back into a Python dictionary for further processing.
You can easily modify this script to suit your specific needs, such as processing multiple files, extracting specific data, or integrating it into a larger application.
## Error Handling
The parser provides detailed error messages when it encounters issues in the KV3 content. The `KV3ParseError` class is used to generate these messages, which include:
- The type of error
- The line and column where the error occurred
- A snippet of the content around the error location
- A pointer to the exact position of the error
## Implementation Details
The parser is implemented as a `KV3Parser` class with the following key methods:
- `parse()`: The main parsing method
- `parse_value()`: Parses different types of values (objects, arrays, strings, numbers, keywords)
- `parse_object()`: Handles parsing of KV3 objects
- `parse_array()`: Handles parsing of arrays
- `parse_string()`: Parses both single-line and multi-line strings
- `parse_number()`: Handles integer and float parsing
- `parse_keyword_or_resource()`: Handles keywords (true, false, null) and resource strings
The parser also includes methods for skipping whitespace and comments, and for parsing keys with potential flags.
The `kv3_to_json()` function provides a convenient wrapper around the `KV3Parser` class, making it easy to convert KV3 content to JSON with a single function call.
## Dependencies
This project requires Python 3.6 or later. It uses only built-in Python libraries (`re` and `json`) and has no external dependencies.
## Contributing
Contributions to improve the parser or extend its functionality are welcome. Please feel free to submit issues or pull requests on the GitHub repository.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Acknowledgments
This parser was created to facilitate data analysis for the game Deadlock. Special thanks to the Deadlock community for their support and feedback.
Raw data
{
"_id": null,
"home_page": null,
"name": "kv3parser",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Zehm <mrtentacleshasallthetalent@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a2/88/dbdfcace6558544e26ec00e30cbf163ef233a1122c56f9a057f6b2caaba1/kv3parser-1.1.tar.gz",
"platform": null,
"description": "# kv3parser\n\nA Python parser for converting KV3 (KeyValues3) data format to JSON, built for data analysis in the game Deadlock.\n\n## Installation\n\nYou can install kv3parser using pip:\n\n```\npip install kv3parser\n```\n\n## Overview\n\nThis project provides a robust parser that can read KV3 formatted data from .vdata files and convert it to JSON. KV3 is a data format used in some Valve games and tools, including Deadlock. By converting KV3 to JSON, this parser facilitates easier analysis and manipulation of game data using standard JSON tools and libraries.\n\n## Features\n\n- Parses KV3 formatted data from .vdata files and converts it to JSON\n- Handles complex KV3 structures including nested objects and arrays\n- Supports various data types: strings, numbers, booleans, null values\n- Recognizes and preserves KV3-specific flags (resource, resourcename, panorama, soundevent, subclass)\n- Provides detailed error messages with line and column information for parsing errors\n- Supports multi-line strings\n- Handles comments (both single-line and multi-line)\n- Allows for flexible syntax, such as omitting commas between key-value pairs\n\n## Usage\n\n```python\nimport json\nfrom kv3parser import kv3_to_json\n\n# Path to your .vdata file\nvdata_file_path = 'path/to/your/file.vdata'\n\n# Read the content of the .vdata file\nwith open(vdata_file_path, 'r', encoding='utf-8') as file:\n vdata_content = file.read()\n\ntry:\n # Parse the KV3 content\n json_output = kv3_to_json(vdata_content)\n \n # Print or save the JSON output\n print(json_output)\n \n # Optionally, save to a file\n with open('output.json', 'w', encoding='utf-8') as json_file:\n json_file.write(json_output)\n\nexcept Exception as e:\n print(f\"Error parsing KV3: {e}\")\n```\n\nThis script does the following:\n\n1. Reads a .vdata file (which uses the KV3 format).\n2. Parses the content using `kv3_to_json()`.\n3. Saves the resulting JSON to a file.\n4. Provides an example of how to load the JSON back into a Python dictionary for further processing.\n\nYou can easily modify this script to suit your specific needs, such as processing multiple files, extracting specific data, or integrating it into a larger application.\n\n## Error Handling\n\nThe parser provides detailed error messages when it encounters issues in the KV3 content. The `KV3ParseError` class is used to generate these messages, which include:\n\n- The type of error\n- The line and column where the error occurred\n- A snippet of the content around the error location\n- A pointer to the exact position of the error\n\n## Implementation Details\n\nThe parser is implemented as a `KV3Parser` class with the following key methods:\n\n- `parse()`: The main parsing method\n- `parse_value()`: Parses different types of values (objects, arrays, strings, numbers, keywords)\n- `parse_object()`: Handles parsing of KV3 objects\n- `parse_array()`: Handles parsing of arrays\n- `parse_string()`: Parses both single-line and multi-line strings\n- `parse_number()`: Handles integer and float parsing\n- `parse_keyword_or_resource()`: Handles keywords (true, false, null) and resource strings\n\nThe parser also includes methods for skipping whitespace and comments, and for parsing keys with potential flags.\n\nThe `kv3_to_json()` function provides a convenient wrapper around the `KV3Parser` class, making it easy to convert KV3 content to JSON with a single function call.\n\n## Dependencies\n\nThis project requires Python 3.6 or later. It uses only built-in Python libraries (`re` and `json`) and has no external dependencies.\n\n## Contributing\n\nContributions to improve the parser or extend its functionality are welcome. Please feel free to submit issues or pull requests on the GitHub repository.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\nThis parser was created to facilitate data analysis for the game Deadlock. Special thanks to the Deadlock community for their support and feedback.",
"bugtrack_url": null,
"license": null,
"summary": "A parser for KV3 file format",
"version": "1.1",
"project_urls": {
"Bug Tracker": "https://github.com/Zehmosu/kv3parser/issues",
"Homepage": "https://github.com/Zehmosu/kv3parser"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "10a46ee90d86fc8272629067a60773cb5dd2f1fb03e0cf597a80cee171bde578",
"md5": "76da4b8340ab6b3fe5f5a6eb5ed6511d",
"sha256": "cbc21051bfe5296ee0c869b9fb8ebb9a297795258dcc5c88c3082a6ece161329"
},
"downloads": -1,
"filename": "kv3parser-1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "76da4b8340ab6b3fe5f5a6eb5ed6511d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5734,
"upload_time": "2024-08-28T04:16:55",
"upload_time_iso_8601": "2024-08-28T04:16:55.341881Z",
"url": "https://files.pythonhosted.org/packages/10/a4/6ee90d86fc8272629067a60773cb5dd2f1fb03e0cf597a80cee171bde578/kv3parser-1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a288dbdfcace6558544e26ec00e30cbf163ef233a1122c56f9a057f6b2caaba1",
"md5": "1fb082632f30f6aeb3dbd793352c8a3e",
"sha256": "044e931f67df92f23ae00d94ed2729b408423e4f51bae7d47f3d79abcb61f285"
},
"downloads": -1,
"filename": "kv3parser-1.1.tar.gz",
"has_sig": false,
"md5_digest": "1fb082632f30f6aeb3dbd793352c8a3e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5057,
"upload_time": "2024-08-28T04:16:57",
"upload_time_iso_8601": "2024-08-28T04:16:57.134805Z",
"url": "https://files.pythonhosted.org/packages/a2/88/dbdfcace6558544e26ec00e30cbf163ef233a1122c56f9a057f6b2caaba1/kv3parser-1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-28 04:16:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Zehmosu",
"github_project": "kv3parser",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "kv3parser"
}