How to get the gender of a first name in Python

Here is an incredibly simple method of determining a name’s gender using one of our free trial APIs. First step is to install the Validate API Client using pip install:

pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.Validate.git

The next step is just to call name_get_gender with this snippet:

from __future__ import print_function
import time
import cloudmersive_validate_api_client
from cloudmersive_validate_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Apikey'] = 'Bearer'
# create an instance of the API class
api_instance = cloudmersive_validate_api_client.NameApi(cloudmersive_validate_api_client.ApiClient(configuration))
input = cloudmersive_validate_api_client.GetGenderRequest() # GetGenderRequest | Gender request information
try:
# Get the gender of a first name
api_response = api_instance.name_get_gender(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling NameApi->name_get_gender: %s\n" % e)

Simple, right? Let’s look at a quick example (ES being the country code for Spain):

{
"FirstName": "Alejandro",
"CountryCode": "ES"
}

This yields the following result:

{
"Successful": true,
"Gender": "Male"
}
Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store