Python example

Convert snake_case to camelCase in Python

Split a predictable snake_case string into underscore-separated tokens, keep the first token lowercase, and capitalize the remaining tokens before joining them.

By Camel Case Converter Editorial TeamPublished Sep 12, 2026Last reviewed

Python code

def snake_to_camel(value: str) -> str:
    parts = [part for part in value.strip("_").split("_") if part]
    if not parts:
        return ""
    head, *tail = parts
    return head.lower() + "".join(part[:1].upper() + part[1:].lower() for part in tail)

print(snake_to_camel("user_profile_image"))
# userProfileImage

The helper removes leading/trailing underscores and empty tokens caused by repeated underscores, producing deterministic output for ordinary snake_case.

Python itself commonly uses snake_case, so this is most useful at JSON, API, generated-client, or JavaScript integration boundaries.

Edge cases to consider

  • Acronym output depends on the consuming system's convention.
  • Nested dictionaries need recursive key conversion, not a string helper alone.
  • Values with capitals, dashes, or spaces need broader tokenization.
  • Prefer conversion at serialization boundaries when the external API contract is fixed.

Example

BeforeAfter
user_profile_imageuserProfileImage
__user__profile__userProfile
api_response_urlapiResponseUrl
created_atcreatedAt

Python code

cases = {
    "user_profile_image": "userProfileImage",
    "__user__profile__": "userProfile",
    "api_response_url": "apiResponseUrl",
    "created_at": "createdAt",
}

for value, expected in cases.items():
    assert snake_to_camel(value) == expected

Try the conversion online

Use the browser-based converter for quick checks, batch values, acronym handling, or inputs that mix several naming conventions.

Detected: snake_case
camelCase output
userProfileImageUrl

All naming formats

camelCase
userProfileImageUrl
PascalCase
UserProfileImageUrl
snake_case
user_profile_image_url
kebab-case
user-profile-image-url
CONSTANT_CASE
USER_PROFILE_IMAGE_URL
dot.case
user.profile.image.url
path/case
user/profile/image/url

Conversion happens locally in your browser. Your input is not sent to a conversion server.