Skip to content

Parse

parse

ProjectMetadata

Bases: TypedDict

Metadata for a Godot project.

Attributes:

Name Type Description
name Optional[str]

Project name.

description Optional[str]

Project description.

version Optional[str]

Project version.

tags Optional[list[str]]

List of tags.

file_path Path

Absolute path to the project file (read-only).

dir_path Path

Absolute path to the project directory (read-only).

icon_path Optional[Path]

Absolute path to the icon file.

engine_version Optional[GodotVersion]

Full engine version string.

compatibility_version Optional[GodotVersion]

Minimum compatible Godot version.

create(project_dir: Path, name: str, description: str = 'A new Godot project.', icon_path: Path | None = None, engine_version: Optional[GodotVersion] = None, tags: list[str] | None = None, git_init: bool = False) -> None

Create a new Godot project with optional icon, version, tags, and Git setup.

Parameters:

Name Type Description Default
project_dir Path

Directory where the project will be created.

required
name str

Name of the project (used for config/name).

required
description str

Optional project description.

'A new Godot project.'
icon_path Optional[Path]

Optional path to a custom icon file.

None
engine_version Optional[GodotVersion]

Optional Godot engine version.

None
tags Optional[list[str]]

Optional list of tags (requires Godot >= 4.0).

None
git_init bool

Whether to initialize a Git repository.

False

Raises:

Type Description
FileExistsError

If project_dir already contains a project.godot file.

GitError

If git_init is set and Git is missing (checked before anything is written) or git init fails.

read(project_path: Path) -> ProjectMetadata

Parse a Godot project.godot file and extract metadata.

Parameters:

Name Type Description Default
project_path Path

Path to the project.godot file.

required

Returns:

Type Description
ProjectMetadata

ProjectMetadata

Raises:

Type Description
FileNotFoundError

If the provided path is not a valid file.

VersionFileError

If the project's .godot-version is malformed.

read_engine_version(project_path: Path) -> GodotVersion | None

Reads the engine version pinned in the project's .godot-version file.

The version is the first line that isn't blank or a # comment (later lines are ignored).

Parameters:

Name Type Description Default
project_path Path

Path to the project file.

required

Returns:

Type Description
GodotVersion | None

The pinned version, or None if the project has no .godot-version.

Raises:

Type Description
VersionFileError

If the file isn't UTF-8 or holds no valid version.

set_engine_version(project_path: Path, engine_version: GodotVersion)

Pins an engine version in the project's .godot-version file.

Writes the canonical form, e.g. 4.3.stable.mono, on one line.

Parameters:

Name Type Description Default
project_path Path

Path to the project file.

required
engine_version GodotVersion

New engine version to write.

required

Raises:

Type Description
FileNotFoundError

If the provided path is not a valid file.

set_project_icon(project_path: Path, icon_path: Path)

Sets the project icon. An icon inside the project is used in place; one outside is copied to the project root under its own name, with -2, -3, … added if a different file already has that name.

Parameters:

Name Type Description Default
project_path Path

Path to the project file.

required
icon_path Path

Path to the icon file.

required

Raises:

Type Description
FileNotFoundError

If the provided path is not a valid file.

update(project_path: Path, metadata: ProjectMetadata) -> None

Writes the fields in metadata that differ from the project file.

A key left out of metadata leaves that field alone. A key set to None clears it (the property is removed from project.godot).

The .godot-version pin is only read by read(), never here, so a malformed pin doesn't block other edits, and setting engine_version (or clearing it) repairs one.

Parameters:

Name Type Description Default
project_path Path

Path to the project.godot file.

required
metadata ProjectMetadata

The fields to change.

required

Raises:

Type Description
FileNotFoundError

If the provided path is not a valid file.

write_properties(project_path: Path, properties: dict[str, str | None], category: str = 'application') -> None

Writes properties to the given project file, replacing existing keys and adding missing ones (and the section, if absent). A None value removes the key.

Parameters:

Name Type Description Default
project_path Path

Path to the project file.

required
properties dict[str, str | None]

Keys mapped to raw Godot values, e.g. {"config/name": '"My Game"'}, or None to remove the key.

required
category str

Section to write the properties into.

'application'

Raises:

Type Description
FileNotFoundError

If the provided path is not a valid file.