{"id":4020,"library":"gender-guesser","title":"Gender Guesser","description":"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.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/lead-ratings/gender-guesser","tags":["gender","name","detection","NLP","utility"],"install":[{"cmd":"pip install gender-guesser","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import gender_guesser.detector as gender; d = gender.Detector()","symbol":"Detector","correct":"from gender_guesser.detector import Detector"}],"quickstart":{"code":"from gender_guesser.detector import Detector\n\nd = Detector()\n\n# Guess gender for a single name\nname1 = \"Peter\"\ngender1 = d.get_gender(name1)\nprint(f\"The gender for {name1} is: {gender1}\")\n\n# Guess gender for a name with country preference\nname2 = \"Andrea\"\ncountry = \"italy\" # Country names must be lowercase with underscores\ngender2 = d.get_gender(name2, country)\nprint(f\"The gender for {name2} in {country} is: {gender2}\")\n\n# Example with a name often considered androgynous\nname3 = \"Pauley\"\ngender3 = d.get_gender(name3)\nprint(f\"The gender for {name3} is: {gender3}\")\n\n# Example with case_sensitive=False\nd_insensitive = Detector(case_sensitive=False)\nname4 = \"sally\"\ngender4 = d_insensitive.get_gender(name4)\nprint(f\"The gender for {name4} (case-insensitive) is: {gender4}\")","lang":"python","description":"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."},"warnings":[{"fix":"Initialize `Detector()` only once in your application and pass the instance around or keep it as a singleton.","message":"Creating multiple `Detector` instances is inefficient as each instance re-reads the data file. Instantiate the detector once and reuse it.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When initializing, set `d = Detector(case_sensitive=False)` for case-insensitive matching, or ensure input names are properly capitalized (e.g., `name.capitalize()`).","message":"By default, the `Detector` is case-sensitive. 'John' might be recognized, but 'john' could be 'unknown'.","severity":"gotcha","affected_versions":"All versions"},{"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ë').","message":"The 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.","severity":"gotcha","affected_versions":"0.3.0+"},{"fix":"Ensure country names are formatted correctly, typically by converting to lowercase and replacing spaces with underscores (e.g., `country_name.lower().replace(' ', '_')`).","message":"When 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'.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"In 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.","severity":"breaking","affected_versions":"<0.3.0 to 0.3.0+"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}