Convert PascalCase to snake_case!

String
Result

Convert PascalCase 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!

Splits PascalCase names into lowercase words joined by underscores: ShippingAddress → shipping_address. Python module names (PEP 8), Rails and Django table names, and database columns use snake_case, while the classes they are named after are PascalCase.

Typical inputs are a list of model classes for which you need table or file names, or C#/Java type names that have to become Python identifiers.

How to use

  1. Choose PascalCase → snake_case.
  2. Paste class names, file paths or type declarations into String.
  3. Copy the snake_case names from Result.

Example

Input (PascalCase)
models/OrderItem.py
models/ShippingAddress.py
models/PaymentMethod.py
Output (snake_case)
models/order_item.py
models/shipping_address.py
models/payment_method.py

Only the file names change; the models/ folder and the .py extension are kept, giving PEP 8 style module names.

Supported features

  • Splits the name into words, lowercases them and joins them with underscores: PaymentMethod → payment_method.
  • Digits stay with their word: Base64Encoder → base64_encoder.
  • Paths and extensions around the name are preserved.

Use cases

Table names for ORM models

Django and Rails derive table names from class names in snake_case. When creating tables by hand or writing raw SQL, converting OrderItem, ShippingAddress gives order_item, shipping_address (add the plural yourself if your convention uses one).

Moving classes into separate Python modules

When splitting a large models.py, each class usually gets a module named after it: PaymentMethod lives in payment_method.py.

Notes and limitations

  • An acronym is kept as one word: XMLParser → xml_parser, IOError → io_error. If two acronyms touch, as in XMLHTTPClient, they merge into xmlhttp_client.
  • One-word class names such as User are not recognized (two capitals are required) and stay unchanged.

FAQ

Why is User not converted to user?

A PascalCase name must contain at least two capitals for this tool, which prevents ordinary capitalized words from being changed. Lowercase single words yourself.

Does it pluralize table names?

No. OrderItem becomes order_item; Rails would use order_items, so add the s where your framework expects it.