Skip to content

Python naming conventions

These rules extend the general naming conventions and PEP 8. Where they overlap, the general rule is canonical; this page adds the Python cases.

Casing summary

Used for Casing Example
Functions, methods, variables, parameters snake_case get_migration_files(), update_start_number
Classes, dataclasses, enums PascalCase DebeeOrchestrator, TestManifest, ObjectType
Enum members SCREAMING_SNAKE_CASE ObjectType.FUNCTION, Operation.CREATE_OR_REPLACE
Module-level constants (incl. compiled regexes) SCREAMING_SNAKE_CASE SUITE_FILE_PATTERN, TEST_DEFAULT_KEYS
Private (module- or class-internal) leading _ _read_test_manifest(), _tests_dir
Environment variables SCREAMING_SNAKE_CASE, as the tool's docs name them DBDESTDB, DBADHOCDIRECTORY
CLI options kebab-case long options, short letters --test-filter, -s

File names

Kind Rule Example
Importable module snake_case (a hyphen can't be imported) users_provider.py, string_helpers.py, check.py
Entry script that is never imported kebab-case allowed, matching the tool's command name extract-db-objects.py, debee.py
Tests test_<module>.py test_users_provider.py
Side-layer modules plural container name string_helpers.py, constants.py, models.py

Classes

Role Name Example
Provider of one resource plural noun + Provider (natural singular for one external system) FilesProvider, PsqlProvider
Workflow noun + Manager — only when a module really needs one MigrationsManager
Tool state holder (single-file CLI) tool name + role DebeeOrchestrator
Model bare singular noun DbObject, ObjectUpdate, TestResult
Helpers module / class plural + Helpers SqlHelpers (or module sql_helpers.py with functions)

Prefer modules of functions over classes of static methods: sql_helpers.normalize_arg_type(), not SqlHelpers.normalize_arg_type(), unless the code is a single file and the class groups them visibly.

Function verbs

The shared verb registry applies in snake_case: create_, update_, delete_, get_, fetch_, load_, search_, process_, map_, check_, validate_, verify_, ensure_, generate_, parse_, copy_, send_. Their meaning doesn't change:

Verb In a Python tool Example
get_ returns data to the caller get_migration_files(directory)
fetch_ one raw call to an outside system, result as sent fetch_catalog_rows(connection)
load_ brings data in and keeps it (fills state, a cache) load_environment(paths) sets os.environ
parse_ text / file content → models parse_sql_objects(content, file_name), parse_arguments(argv)
generate_ builds new data or text from inputs generate_markdown(objects), generate_html(objects, template)
map_ model → model / output shape map_object_to_row(db_object)
save_ writes and persists (a file) save_text(path, text)
check_ read-only verdict check_versions_match(versions)
validate_ gate at the boundary; raises validate_search_path(value)
ensure_ creates if missing, returns it ensure_output_folder(path)

Tool-specific verbs a CLI needs, kept to this closed list:

Verb Means Example
run_ start an external process or a named operation and wait run_psql(args), run_tests()
print_ write a human message to stderr (I/O layer) print_info(), print_warning()
confirm_ ask the user, return the answer confirm_production()
classify_ put one input into one of a closed set of categories classify_test_line(line)
resolve_ turn a reference into the real thing (path, name → id) resolve_tests_dir()
extract_ pull structured data out of a larger input (many files → models), no side effects extract_objects(files)

Avoid verbs that say nothing: do_, handle_ (outside event handlers), output_, process_ for anything that isn't bulk processing, manage_.

CLI operations keep their name

A function that implements a named CLI operation keeps the operation's name in snake_case: recreateDatabase → recreate_database(), runTests → run_tests(), prepareVersionTable → prepare_version_table(). The operation name is the ubiquitous language the user types; the code follows it, even when the verb isn't in the registry. (PowerShell has to map these to approved verbs — see the PowerShell naming page.)

Predicates

  • Functions returning bool read as a question: is_adhoc_file(path), has_failures(result), can_connect(), should_cleanup(manifest).
  • Boolean variables and fields use the same prefixes: is_adhoc, has_adhoc_updates, always_cleanup (a setting named by the tool's config key stays as the key).
  • A predicate never prints and never raises for the "false" case.

Names say what the value holds

The general rule Say what the value holds applies with full force in Python, where there are no declared types at the call site:

Bad Good Why
obj, u, d, x db_object, update, manifest single letters only for i / j indexes and _ throwaways
files (of names) file_names / file_paths str vs Path
live live_overloads what is live?
last (a tuple) last_update: ObjectUpdate named parts → a model
js_data, cfg, env table_rows, config, environment no abbreviations
data, result, info objects_by_key, test_result name the content

Collections are plural (objects, test_items); dictionaries say their key: objects_by_key, files_by_suite.

Anti-patterns

  • String-keyed dicts as models — use a dataclass (see the index).
  • Progress messages on stdout of a tool whose result goes to stdout.
  • Import inside a function to avoid a top-level import (import re inside generate_html) — imports go at the top.
  • A function that both computes and prints — return the value; let the I/O layer print.
  • Copy-pasted loops that split or format the same records in two output formats — one mapper, used by every format.
  • except Exception: pass — catch the exception you expect, or let it reach main().