Convert snake_case to kebab-case!

String
Result

Convert snake_case to kebab-case!

Is the variable naming in the code you copied from somewhere else different from your code? Don't worry! It converts variables to your desired naming convention!

Replaces the underscores in snake_case names with hyphens: output_dir → output-dir. Hyphenated lowercase names are the norm for long command-line options, URL paths, Kubernetes resource names, npm package names and CSS classes, none of which use underscores by convention.

A common case is a Python script whose argparse options or config keys were written with underscores and now need the conventional --flag-name form, or database identifiers that have to appear in URLs.

How to use

  1. Set the pair to snake_case → kebab-case.
  2. Paste the flags, keys or path segments into String, one per line or inline.
  3. Copy the Result text.

Example

Input (snake_case)
--dry_run
--output_dir dist
--max_workers 4
Output (kebab-case)
--dry-run
--output-dir dist
--max-workers 4

Each option name gets hyphens, and the leading -- and the values dist and 4 are kept. In argparse, --dry-run is still read as args.dry_run, so the Python side does not change.

Supported features

  • Every underscore inside a name becomes a hyphen: max_workers → max-workers, address_line_2 → address-line-2.
  • Text around the name, such as --, / or ?page=, is preserved.
  • A single leading underscore is removed: _internal_id → internal-id.

Use cases

Cleaning up CLI options

argparse and click accept --output_dir, but users expect --output-dir. Converting the option list and updating the add_argument calls keeps the attribute names (output_dir) the same.

URL slugs from database keys

Category codes like gift_cards or order_history stored in a table can be turned into /gift-cards and /order-history paths, which are the more common style for public URLs.

Notes and limitations

  • Names with a leading double underscore, such as __version__, are not matched and keep their underscores.
  • When pasting whole Python lines, function names like add_argument and keywords like store_true are also converted, which breaks the code. Paste only the names.

FAQ

Are hyphenated names valid Python identifiers?

No. kebab-case is for strings such as options, URLs, file names and resource names; keep Python variables in snake_case.

Does Kubernetes accept the result as a resource name?

Kubernetes names allow lowercase letters, digits and hyphens, and that is exactly what this produces from normal snake_case input, including digit segments.