Registry / ai-ml / gender-guesser

gender-guesser

JSON →
library0.4.0pypypi✓ verified 24d ago

gender-guesser is a Python library that attempts to determine the gender of a person based on their first name. It's a Python port of a Java library and is currently at version 0.4.0. The library returns one of six possible values: 'unknown', 'andy' (androgynous), 'male', 'female', 'mostly_male', or 'mostly_female'. It appears to be actively maintained, with the latest release from late 2016.

pip install gender-guesser
INSTALL
IMPORT
SIG · GENDER-GUESSER
G
gender-guesser
ai-mlpythonv0.4.0
Install
1.6s avg
Import
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 22MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Detector
from gender_guesser.detector import Detector
import gender_guesser.detector as gender; d = gender.Detector()
While 'import gender_guesser.detector as gender' followed by 'gender.Detector()' is common in examples, directly importing 'Detector' is cleaner if only that class is needed.

Initialize the Detector and use the `get_gender()` method. Names should ideally be capitalized for accurate results. Optionally, provide a country code (lowercase, with underscores for spaces) for more refined guessing.

from gender_guesser.detector import Detector d = Detector() # Guess gender for a single name name1 = "Peter" gender1 = d.get_gender(name1) print(f"The gender for {name1} is: {gender1}") # Guess gender for a name with country preference name2 = "Andrea" country = "italy" # Country names must be lowercase with underscores gender2 = d.get_gender(name2, country) print(f"The gender for {name2} in {country} is: {gender2}") # Example with a name often considered androgynous name3 = "Pauley" gender3 = d.get_gender(name3) print(f"The gender for {name3} is: {gender3}") # Example with case_sensitive=False d_insensitive = Detector(case_sensitive=False) name4 = "sally" gender4 = d_insensitive.get_gender(name4) print(f"The gender for {name4} (case-insensitive) is: {gender4}")
Debug
Known issues
gotchaCreating multiple `Detector` instances is inefficient as each instance re-reads the data file. Instantiate the detector once and reuse it.
fix
Initialize `Detector()` only once in your application and pass the instance around or keep it as a singleton.
affects: All versions
gotchaBy default, the `Detector` is case-sensitive. 'John' might be recognized, but 'john' could be 'unknown'.
fix
When initializing, set `d = Detector(case_sensitive=False)` for case-insensitive matching, or ensure input names are properly capitalized (e.g., `name.capitalize()`).
affects: All versions
gotchaThe library differentiates between 'unknown' and 'andy'. 'unknown' means the name was not found in the database. 'andy' means the name was found but has an equal probability of being male or female.
fix
Understand these return values when interpreting results. If `country` is provided, some names might return `andy` whereas without a country, they might return `female` or `male` (e.g., 'Zoë').
affects: 0.3.0+
gotchaWhen providing a country to `get_gender()`, the country name must be in lowercase with spaces replaced by underscores (e.g., 'great_britain', 'the_netherlands'). Invalid country names will raise an error or return 'unknown'.
fix
Ensure country names are formatted correctly, typically by converting to lowercase and replacing spaces with underscores (e.g., `country_name.lower().replace(' ', '_')`).
affects: All versions
breakingIn version 0.3.0, the `unknown_value` initialization option was removed. Additionally, the return values for names not found or equally probable were standardized to 'unknown' and 'andy' respectively.
fix
Remove any usage of `unknown_value` in `Detector` initialization. Adjust code to handle 'unknown' and 'andy' as distinct return values if upgrading from versions prior to 0.3.0.
affects: <0.3.0 to 0.3.0+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'gender_guesser'
The 'gender-guesser' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install gender-guesser'.
AttributeError: 'Gender' object has no attribute 'male'
Attempting to access a non-existent attribute 'male' on a 'Gender' object.
fix
Ensure the 'Gender' class has the 'male' attribute defined, or use the correct attribute name.
unknown
The 'gender_guesser' library returns 'unknown' when it cannot determine the gender of a name.
fix
Verify that the input name is correctly formatted and exists in the library's database.
ModuleNotFoundError: No module named 'gender-guesser'
The 'gender-guesser' package has not been installed in your Python environment.
fix
pip install gender-guesser
AttributeError: module 'gender_guesser' has no attribute 'Detector'
The 'Detector' class is located within the 'detector' submodule, and is not directly accessible from the top-level 'gender_guesser' package.
fix
import gender_guesser.detector as gender
d = gender.Detector()
Upgrade
Version history
0.4.0latest on PyPI · released Dec 5, 2016
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
14
OpenAI (training)
1
Resources
gender-guesser — pip install gender-guesser · libregistry