The Fuchsia project follows the Google Python style guide{:.external}, with a few refinements.
The Google Python style guide allows more variation (presumably to cover a large breadth of existing source). This guide has a tighter set of choices. So a Fuchsia Python file will also comply with the Google style guide, but a Google Python file might not comply with this guide. See refinements below for details.
Fuchsia vendors its own Python 3 interpreter in the checkout (//scripts/fuchsia-vendored-python, currently Python 3.11 or later as of 2026-08).
All executable Python scripts in the Fuchsia repository must begin with the following shebang line:
#!/usr/bin/env fuchsia-vendored-python
For more information, see RFC-0129 and Build system policies.
The following refinements we make to the Google Python style guide are largely choices between variations. For example, if the style guide says you may do A, B, or C we may choose to favor B and avoid the other choices.
Avoid aligning with opening delimiter. Prefer instead to indent using fixed (4 space) indentation.
(See Indentation{:.external} in the Google Python style guide for comparison.)
Avoid creating single line statements, even with if statements.
Yes: if foo: bar(foo)
No: if foo: bar(foo)
(See Statements{:.external} in the Google Python style guide for comparison.)
Type annotations are strongly encouraged for all new Python code in Fuchsia. Follow modern Python (3.11+) type annotation conventions in accordance with the Google Python Style Guide{:.external}:
list[str], dict[str, int], set[Path], tuple[int, ...]). Do not import List, Dict, Set, Tuple from typing.| operator for union types (int | float, str | None). Do not import Union or Optional from typing.Prefer double quotes for strings ("). Use single quotes when the declaration is more readable with single quotes. For example, 'The cat said "Meow"' is more readable than "The cat said \\"Meow\\"".
Prefer f-strings (f"...") for string formatting and interpolation over % formatting or .format(). Maintain double quotes for f-strings.
(See Strings{:.external} in the Google Python style guide for comparison.)
Be consistent within a large scope. Avoid displaying small pockets of consistency within Fuchsia. Being consistent within only a single file or directory is not consistency.
Within third_party, the intent is to follow the existing style for that project or library. Look for a style guide within that library as appropriate.
(See Parting Words{:.external} in the Google Python style guide.)