Convert kebab-case to snake_case!

String
Result

Convert kebab-case to snake_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!

Swaps hyphens for underscores in kebab-case names: order-history → order_history. URL paths, query parameters, CLI flags and file names are often hyphenated, while Python variables, SQL columns and many analytics or logging schemas only allow underscores.

Paste the routes, query keys or flag names and get identifiers you can use in Python code, database columns or event properties.

How to use

  1. Pick kebab-case as the source and snake_case as the target.
  2. Paste URLs, query strings or option names into String.
  3. Copy the renamed text from Result.

Example

Input (kebab-case)
GET /api/order-history?page-size=20
GET /api/gift-cards/balance-check
Output (snake_case)
GET /api/order_history?page_size=20
GET /api/gift_cards/balance_check

Path segments and the page-size query key are converted; GET, /api and the number 20 are untouched.

Supported features

  • Replaces each hyphen inside a name with an underscore: balance-check → balance_check.
  • Keeps slashes, ?, = and other URL characters around the names.
  • Leaves dates and version numbers such as 2024-01-01 alone.

Use cases

Route names to Python handlers

Flask and FastAPI paths like /gift-cards/balance-check usually map to functions named balance_check. Converting the route list gives the function names to implement.

Tracking parameters to warehouse columns

Query parameters such as utm-source or ref-code that land in BigQuery or Snowflake are typically stored as utm_source, ref_code columns.

Notes and limitations

  • Digit segments are converted too: item-2 becomes item_2, which keeps it a valid Python identifier.
  • Domain names with hyphens are converted as well (my-shop.com → my_shop.com). Keep hosts out of the input.

FAQ

Is the result safe for Python identifiers?

For names made of letters and hyphens, yes. If a name starts with a digit, Python still won't accept it as an identifier.

Does Python's argparse need this?

No. argparse already turns --dry-run into args.dry_run. This page is for when you want to write those names elsewhere, such as config keys or docs.