unityparser


Nameunityparser JSON
Version 4.0.0 PyPI version JSON
download
home_pagehttps://github.com/socialpoint-labs/unity-yaml-parser
SummaryA python library to parse and dump Unity YAML files
upload_time2024-04-12 09:28:19
maintainerNone
docs_urlNone
authorRicard Valverde
requires_python>=3.7.0
licenseMIT License
keywords unity yaml parser serializer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Unity YAML Parser #

This project aims to provide a python3 API to load and dump Unity YAML 
files(configurations, prefabs, scenes, serialized data, etc) in the exact same 
format the internal Unity YAML serializer does.

Using this API you will be able to easily manipulate(as python objects) 
Unity YAML files and save them just the same, keeping the YAML structure
exactly as Unity does. This has the advantages of, first not having to
configure PyYAML beforehand to deal with Unity YAMLs, and second as the
modified file keeps the same structure and formatting that Unity does, 
when the YAML file is loaded by Unity it won't make formatting changes 
to it that will make any VCS report unexpected file changes.

## Installing ##

Install and update using [pip](https://pip.pypa.io/en/stable/quickstart/):
````
pip install -U unityparser
````
## A Simple Example ##
````python
from unityparser import UnityDocument

# Loading and modifying a config file with a single YAML document
project_settings_file = 'UnityProject/ProjectSettings/ProjectSettings.asset'
doc = UnityDocument.load_yaml(project_settings_file)
ProjectSettings = doc.entry
ProjectSettings.scriptingDefineSymbols[1] += ';CUSTOM_DEFINE'
ProjectSettings.scriptingDefineSymbols[7] = ProjectSettings.scriptingDefineSymbols[1]
doc.dump_yaml()

# You can also load YAML files with multiple documents and filter for a single or multiple entries
hero_prefab_file = 'UnityProject/Assets/Prefabs/Hero.prefab'
doc = UnityDocument.load_yaml(hero_prefab_file)
# accessing all entries
doc.entries
# [<UnityClass>, <UnityClass>, ...]
# accessing first entry
doc.entry
# <UnityClass>
# get single entry uniquely defined by filters
entry = doc.get(class_name='MonoBehaviour', attributes=('m_MaxHealth',))
entry.m_MaxHealth += 10
# get multiple entries matching a filter
entries = doc.filter(class_names=('MonoBehaviour',), attributes=('m_Enabled',))
for entry in entries:
    entry.m_Enabled = 1
doc.dump_yaml()
# calling entry method for a doc with multiple document will return the first one
print(doc.entry.__class__.__name__)
# 'Prefab'
````

## Classes ##

### unityparser.UnityDocument ###

Main class to load and dump files.

#### unityparser.UnityDocument.load_yaml(file_path) ####

_**Classmethod**_: Load the given YAML file_path and return a UnityDocument file

#### unityparser.UnityDocument.dump_yaml(file_path=None) ####

Dump the UnityDocument to the previously loaded file location(overwrite). 
If *file_path* argument is provided, dump the document to the specified location instead.

This method **keeps line endings** of the original file when it dumps.

#### unityparser.UnityDocument.entries ####

_**Property**_: Return the _list_ of documents found in the YAML. The objects in the _list_ are of _types_ Class named after the serialized Unity class(ie. MonoBehaviour, GameObject, Prefab, CustomName, etc).

#### unityparser.UnityDocument.entry ####

_**Property**_: Return the first document in the YAML, useful if there is only one. Equivalent of doing `UnityDocument.entries[0]`.

#### unityparser.UnityDocument.get(class_name=None, attributes=None) ####

_**Method**_: Return a single entry uniquely matching the given filters. Must exist exactly one.

#### unityparser.UnityDocument.filter(class_names=None, attributes=None) ####

_**Method**_: Return a list of entries matching the given filters. Many or none can be matched.

### unityparser.loader.UnityLoader ###

PyYAML's Loader class, can be used directly with PyYAML to customise loading. 

### unityparser.dumper.UnityDumper ###

PyYAML's Dumper class, can be used directly with PyYAML to customise dumping. 

## Considerations ##

Text scalars which are single or double quoted that span multiple lines are not being dumped exactly as Unity does. There's a difference in the maximum length allowed per line and the logic to wrap them.




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/socialpoint-labs/unity-yaml-parser",
    "name": "unityparser",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7.0",
    "maintainer_email": null,
    "keywords": "unity, yaml, parser, serializer",
    "author": "Ricard Valverde",
    "author_email": "ricard.valverde@socialpoint.es",
    "download_url": "https://files.pythonhosted.org/packages/c9/e9/dec6a16fb88a154805f01a279353a6fa5002c15be069211f7d6c4211fadf/unityparser-4.0.0.tar.gz",
    "platform": null,
    "description": "# Unity YAML Parser #\n\nThis project aims to provide a python3 API to load and dump Unity YAML \nfiles(configurations, prefabs, scenes, serialized data, etc) in the exact same \nformat the internal Unity YAML serializer does.\n\nUsing this API you will be able to easily manipulate(as python objects) \nUnity YAML files and save them just the same, keeping the YAML structure\nexactly as Unity does. This has the advantages of, first not having to\nconfigure PyYAML beforehand to deal with Unity YAMLs, and second as the\nmodified file keeps the same structure and formatting that Unity does, \nwhen the YAML file is loaded by Unity it won't make formatting changes \nto it that will make any VCS report unexpected file changes.\n\n## Installing ##\n\nInstall and update using [pip](https://pip.pypa.io/en/stable/quickstart/):\n````\npip install -U unityparser\n````\n## A Simple Example ##\n````python\nfrom unityparser import UnityDocument\n\n# Loading and modifying a config file with a single YAML document\nproject_settings_file = 'UnityProject/ProjectSettings/ProjectSettings.asset'\ndoc = UnityDocument.load_yaml(project_settings_file)\nProjectSettings = doc.entry\nProjectSettings.scriptingDefineSymbols[1] += ';CUSTOM_DEFINE'\nProjectSettings.scriptingDefineSymbols[7] = ProjectSettings.scriptingDefineSymbols[1]\ndoc.dump_yaml()\n\n# You can also load YAML files with multiple documents and filter for a single or multiple entries\nhero_prefab_file = 'UnityProject/Assets/Prefabs/Hero.prefab'\ndoc = UnityDocument.load_yaml(hero_prefab_file)\n# accessing all entries\ndoc.entries\n# [<UnityClass>, <UnityClass>, ...]\n# accessing first entry\ndoc.entry\n# <UnityClass>\n# get single entry uniquely defined by filters\nentry = doc.get(class_name='MonoBehaviour', attributes=('m_MaxHealth',))\nentry.m_MaxHealth += 10\n# get multiple entries matching a filter\nentries = doc.filter(class_names=('MonoBehaviour',), attributes=('m_Enabled',))\nfor entry in entries:\n    entry.m_Enabled = 1\ndoc.dump_yaml()\n# calling entry method for a doc with multiple document will return the first one\nprint(doc.entry.__class__.__name__)\n# 'Prefab'\n````\n\n## Classes ##\n\n### unityparser.UnityDocument ###\n\nMain class to load and dump files.\n\n#### unityparser.UnityDocument.load_yaml(file_path) ####\n\n_**Classmethod**_: Load the given YAML file_path and return a UnityDocument file\n\n#### unityparser.UnityDocument.dump_yaml(file_path=None) ####\n\nDump the UnityDocument to the previously loaded file location(overwrite). \nIf *file_path* argument is provided, dump the document to the specified location instead.\n\nThis method **keeps line endings** of the original file when it dumps.\n\n#### unityparser.UnityDocument.entries ####\n\n_**Property**_: Return the _list_ of documents found in the YAML. The objects in the _list_ are of _types_ Class named after the serialized Unity class(ie. MonoBehaviour, GameObject, Prefab, CustomName, etc).\n\n#### unityparser.UnityDocument.entry ####\n\n_**Property**_: Return the first document in the YAML, useful if there is only one. Equivalent of doing `UnityDocument.entries[0]`.\n\n#### unityparser.UnityDocument.get(class_name=None, attributes=None) ####\n\n_**Method**_: Return a single entry uniquely matching the given filters. Must exist exactly one.\n\n#### unityparser.UnityDocument.filter(class_names=None, attributes=None) ####\n\n_**Method**_: Return a list of entries matching the given filters. Many or none can be matched.\n\n### unityparser.loader.UnityLoader ###\n\nPyYAML's Loader class, can be used directly with PyYAML to customise loading. \n\n### unityparser.dumper.UnityDumper ###\n\nPyYAML's Dumper class, can be used directly with PyYAML to customise dumping. \n\n## Considerations ##\n\nText scalars which are single or double quoted that span multiple lines are not being dumped exactly as Unity does. There's a difference in the maximum length allowed per line and the logic to wrap them.\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A python library to parse and dump Unity YAML files",
    "version": "4.0.0",
    "project_urls": {
        "Homepage": "https://github.com/socialpoint-labs/unity-yaml-parser"
    },
    "split_keywords": [
        "unity",
        " yaml",
        " parser",
        " serializer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "634c0fec58bda9a18d7beb1e9d7b2b39d9c691890b6de1b165ac9ca518db3784",
                "md5": "7b92c43fb47bdc570f4fd3ba27010e89",
                "sha256": "8a91e81423e5e0280029d32ff3b8456e5a616dcf76ec0d70cac717f17e3ad5fe"
            },
            "downloads": -1,
            "filename": "unityparser-4.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7b92c43fb47bdc570f4fd3ba27010e89",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.0",
            "size": 19306,
            "upload_time": "2024-04-12T09:28:18",
            "upload_time_iso_8601": "2024-04-12T09:28:18.408148Z",
            "url": "https://files.pythonhosted.org/packages/63/4c/0fec58bda9a18d7beb1e9d7b2b39d9c691890b6de1b165ac9ca518db3784/unityparser-4.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9e9dec6a16fb88a154805f01a279353a6fa5002c15be069211f7d6c4211fadf",
                "md5": "04e34760a2b54b61a26bd53627bdc871",
                "sha256": "2ebfe30327a6c8be89326edc9d768483bd850e16de80428c836a349bac389595"
            },
            "downloads": -1,
            "filename": "unityparser-4.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "04e34760a2b54b61a26bd53627bdc871",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.0",
            "size": 19105,
            "upload_time": "2024-04-12T09:28:19",
            "upload_time_iso_8601": "2024-04-12T09:28:19.681226Z",
            "url": "https://files.pythonhosted.org/packages/c9/e9/dec6a16fb88a154805f01a279353a6fa5002c15be069211f7d6c4211fadf/unityparser-4.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-12 09:28:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "socialpoint-labs",
    "github_project": "unity-yaml-parser",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "unityparser"
}
        
Elapsed time: 0.19905s