Nameparser
Nameparser is a simple Python module designed for parsing human names into their distinct components, such as title, first, middle, last, suffix, and nickname. It supports a variety of common name formats for Latin-based languages and is currently at version 1.1.3, receiving updates for bug fixes and feature enhancements.
Warnings
- breaking The `full_name` attribute's behavior changed. Before v1.0.4, it returned the original input string. Since v1.0.4, it returns a formatted string output based on the parsed components.
- breaking Version 1.0.0 introduced significant refactoring of prefix handling and support for prefixes on first names, which may alter parsing results for certain names compared to older versions.
- gotcha If you customize the parser's constants (e.g., adding new titles, prefixes, suffixes) after a `HumanName` instance has been created or its `full_name` attribute set, you must explicitly call `name.parse_full_name()` to re-parse the name and apply the new configurations.
- gotcha By default, `HumanName` will not adjust the capitalization of names that are already in mixed case. It primarily corrects all upper or all lower case names.
- gotcha The library is primarily designed for English names. While it can be useful for other Latin-based languages, it may not perform optimally for languages with significantly different name structures without custom configuration.
Install
-
pip install nameparser
Imports
- HumanName
from nameparser import HumanName
Quickstart
from nameparser import HumanName
name = HumanName("Dr. Juan Q. Xavier de la Vega III (Doc Vega)")
print(f"Title: {name.title}")
print(f"First: {name.first}")
print(f"Middle: {name.middle}")
print(f"Last: {name.last}")
print(f"Suffix: {name.suffix}")
print(f"Nickname: {name.nickname}")
print(f"Full Name (formatted): {name}")