{"id":19253419,"url":"https://github.com/stevearc/godot_parser","last_synced_at":"2025-04-05T22:03:29.421Z","repository":{"id":40549495,"uuid":"273727086","full_name":"stevearc/godot_parser","owner":"stevearc","description":"Python library for parsing Godot scene files","archived":false,"fork":false,"pushed_at":"2025-03-11T05:33:50.000Z","size":68,"stargazers_count":63,"open_issues_count":4,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T21:02:44.735Z","etag":null,"topics":["godot","python","tres","tscn"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevearc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-20T14:47:53.000Z","updated_at":"2025-03-26T01:49:04.000Z","dependencies_parsed_at":"2024-06-21T15:45:34.973Z","dependency_job_id":"aa5b6ded-a5f2-4ef9-a23c-89ede2673440","html_url":"https://github.com/stevearc/godot_parser","commit_stats":{"total_commits":67,"total_committers":6,"mean_commits":"11.166666666666666","dds":"0.13432835820895528","last_synced_commit":"bdc74487e196f8a37c673409cd659b1e70b67453"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevearc%2Fgodot_parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevearc%2Fgodot_parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevearc%2Fgodot_parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevearc%2Fgodot_parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevearc","download_url":"https://codeload.github.com/stevearc/godot_parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406084,"owners_count":20933803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["godot","python","tres","tscn"],"created_at":"2024-11-09T18:30:47.149Z","updated_at":"2025-04-05T22:03:29.395Z","avatar_url":"https://github.com/stevearc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Godot Parser\n\n[![Build Status](https://github.com/stevearc/godot_parser/actions/workflows/tests.yml/badge.svg)](https://github.com/stevearc/godot_parser/actions)\n[![Coverage Status](https://coveralls.io/repos/github/stevearc/godot_parser/badge.svg?branch=master)](https://coveralls.io/github/stevearc/godot_parser?branch=master)\n[![Downloads](http://pepy.tech/badge/godot_parser)](https://pypi.org/pypi/godot_parser)\n\nThis is a python library for parsing Godot scene (.tscn) and resource (.tres)\nfiles. It's intended to make it easier to automate certain aspects of editing\nscene files or resources in Godot.\n\n## High-level API\ngodot_parser has roughly two levels of API. The low-level API has no\nGodot-specific logic and is just a dumb wrapper for the file format.\n\nThe high-level API has a bit of application logic on top to mirror Godot\nfunctionality and make it easier to perform certain tasks. Let's look at an\nexample by creating a new scene file for a Player:\n\n```python\n  from godot_parser import GDScene, Node\n\n  scene = GDScene()\n  res = scene.add_ext_resource(\"res://PlayerSprite.png\", \"PackedScene\")\n  with scene.use_tree() as tree:\n      tree.root = Node(\"Player\", type=\"KinematicBody2D\")\n      tree.root.add_child(\n          Node(\n              \"Sprite\",\n              type=\"Sprite\",\n              properties={\"texture\": res.reference},\n          )\n      )\n  scene.write(\"Player.tscn\")\n```\n\nIt's much easier to use the high-level API when it's available, but it doesn't\ncover everything. Note that `use_tree()` *does* support inherited scenes, and\nwill generally function as expected (e.g. nodes on the parent scene will be\navailable, and making edits will properly override fields in the child scene).\nThere is no support yet for changing the inheritence of a scene.\n\n## Low-level API\nLet's look at creating that same Player scene with the low-level API:\n\n```python\n  from godot_parser import GDFile, ExtResource, GDSection, GDSectionHeader\n\n  scene = GDFile(GDSection(GDSectionHeader(\"gd_scene\", load_steps=2, format=2)))\n  scene.add_section(\n      GDSection(\n          GDSectionHeader(\n              \"ext_resource\", path=\"res://PlayerSprite.png\", type=\"PackedScene\", id=1\n          )\n      )\n  )\n  scene.add_section(\n      GDSection(GDSectionHeader(\"node\", name=\"Player\", type=\"KinematicBody2D\"))\n  )\n  scene.add_section(\n      GDSection(\n          GDSectionHeader(\"node\", name=\"Sprite\", type=\"Sprite\", parent=\".\"),\n          texture=ExtResource(1),\n      )\n  )\n  scene.write(\"Player.tscn\")\n```\n\nYou can see that this requires you to manage more of the application logic\nyourself, such as resource IDs and node structure, but it can be used to create\nany kind of TSCN file.\n\n## More Examples\nHere are some more examples of how you can use this library.\n\nFind all scenes in your project with a \"Sensor\" node and change the\n`collision_layer`:\n\n```python\n  import os\n  import sys\n  from godot_parser import load\n\n\n  def main(project):\n      for root, _dirs, files in os.walk(project):\n          for file in files:\n              if os.path.splitext(file)[1] == \".tscn\":\n                  update_collision_layer(os.path.join(root, file))\n\n\n  def update_collision_layer(filepath):\n      scene = load(filepath)\n      updated = False\n      with scene.use_tree() as tree:\n          sensor = tree.get_node(\"Sensor\")\n          if sensor is not None:\n              sensor[\"collision_layer\"] = 5\n              updated = True\n\n      if updated:\n          scene.write(filepath)\n\n\n  main(sys.argv[1])\n```\n\n## Caveats\nThis was written with the help of the [Godot TSCN\ndocs](https://godot-es-docs.readthedocs.io/en/latest/development/file_formats/tscn.html),\nbut it's still mostly based on visual inspection of the Godot files I'm working\non. If you find a situation godot_parser doesn't handle or a feature it doesn't\nsupport, file an issue with the scene file and an explanation of the desired\nbehavior. If you want to dig in and submit a pull request, so much the better!\n\nIf you want to run a quick sanity check for this tool, you can use the\n`test_parse_files.py` script. Pass in your root Godot directory and it will\nverify that it can correctly parse and re-serialize all scene and resource files\nin your project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevearc%2Fgodot_parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevearc%2Fgodot_parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevearc%2Fgodot_parser/lists"}