DevBolt
Processed in your browser. Your data never leaves your device.

Python Case Converter

Convert text between naming conventions for Python projects. Transform between snake_case, camelCase, PascalCase, and more, then use the Python code examples for programmatic conversion. All processing is client-side.

← Back to tools

Text Case Converter

Convert text between camelCase, snake_case, kebab-case, and more. Results update as you type.

About Case Conversion

  • Automatically detects word boundaries from camelCase, separators (hyphens, underscores, dots, slashes), and whitespace.
  • Supports 11 case styles commonly used in programming, CSS, file paths, and documentation.
  • Everything runs in your browser — no data is sent over the network.

Python naming conventions (PEP 8)

PEP 8 defines Python's naming conventions: variables and functions use snake_case (my_variable, calculate_total). Classes use PascalCase (MyClass, HttpResponse). Constants use UPPER_SNAKE_CASE (MAX_RETRIES, API_BASE_URL). Module names use lowercase (my_module.py). Private attributes use leading underscore (_internal_value). Name-mangled attributes use double underscore (__private). When working with APIs that use camelCase (JavaScript conventions), you need to convert between cases at the API boundary.

How to convert between cases in Python

Snake to camel: def to_camel(s): parts = s.split('_'); return parts[0] + ''.join(p.capitalize() for p in parts[1:]). Snake to Pascal: def to_pascal(s): return ''.join(p.capitalize() for p in s.split('_')). Camel/Pascal to snake: import re; def to_snake(s): return re.sub(r'(?<=[a-z0-9])(?=[A-Z])', '_', s).lower(). For production code, use the inflection library: pip install inflection; inflection.underscore('CamelCase') returns 'camel_case'; inflection.camelize('snake_case') returns 'SnakeCase'.

Converting API responses between Python and JavaScript conventions

When Python APIs interact with JavaScript frontends, you often need to convert dict keys between snake_case and camelCase. Recursive converter: def keys_to_camel(d): if isinstance(d, dict): return {to_camel(k): keys_to_camel(v) for k, v in d.items()}; if isinstance(d, list): return [keys_to_camel(i) for i in d]; return d. Libraries: pydantic's model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) handles this automatically. FastAPI + Pydantic make case conversion seamless between Python backend and React frontend.

Frequently Asked Questions

What naming convention should I use in Python?

Follow PEP 8: snake_case for variables, functions, and methods; PascalCase for class names; UPPER_SNAKE_CASE for constants. Module and package names use lowercase. These conventions are enforced by linters like flake8, pylint, and ruff.

How do I convert camelCase to snake_case in Python?

Use regex: import re; re.sub(r'(?<=[a-z0-9])(?=[A-Z])', '_', 'camelCase').lower() returns 'camel_case'. For production use, the inflection library handles edge cases: inflection.underscore('HTMLParser') returns 'html_parser'.

How do I convert dict keys from camelCase to snake_case in Python?

Recursively convert keys: def to_snake_keys(d): return {to_snake(k): to_snake_keys(v) if isinstance(v, (dict, list)) else v for k, v in d.items()} for dicts, or use humps library: pip install pyhumps; humps.decamelize(data) converts all keys recursively.

Related Convert Tools