Inflector for Python

3.1.1 · active · verified Sat Apr 11

Inflector is a Python library (version 3.1.1) designed for transforming strings, primarily focusing on pluralizing and singularizing English and Spanish nouns. It also provides utilities for converting strings between various cases like CamelCase, snake_case, and human-readable formats. It serves as a port of the Ruby on Rails Inflector, with Spanish language support developed independently. The project sees infrequent but notable updates, with the latest release in January 2024.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `Inflector` class, instantiate it, and use its core methods like `pluralize`, `singularize`, `underscore`, and `camelize` for common string transformations.

from inflector import Inflector

inflector = Inflector()

# Pluralization
print(f"Plural of 'cat': {inflector.pluralize('cat')}")
print(f"Plural of 'person': {inflector.pluralize('person')}")

# Singularization
print(f"Singular of 'cats': {inflector.singularize('cats')}")
print(f"Singular of 'people': {inflector.singularize('people')}")

# CamelCase to underscore
print(f"Underscore 'CamelCase': {inflector.underscore('CamelCase')}")

# Underscore to CamelCase
print(f"Camelize 'device_type': {inflector.camelize('device_type')}")
print(f"Camelize 'device_type' (lower first): {inflector.camelize('device_type', False)}")

view raw JSON →