Perform Profanity and Obscene Language Analysis and Detection on Text in Python

2 min readJan 13, 2022


Content moderation is important for everyone — no one wants profane or obscene language floating around in their system. Using the /nlp-v2/analytics/profanity iteration of the Cloudmersive NLP API v2, you can empower your application to quickly analyze any given text input for profane or obscene language. The response will provide you with a Profanity Score to gauge how inappropriate a given body of text is. It’s easy to get set up with our ready-to-run, conveniently documented code in Python.

Before we can call the API, we’ll first need to install the SDK in Python, using the below snippet:

pip install cloudmersive-nlp-api-clientfrom __future__ import print_function
import time
import cloudmersive_nlp_api_client
from import ApiException
from pprint import pprint

After that, you’ll need to copy the next snippet to input your API key for authorized access to the API:

# Configure API key authorization: Apikey
configuration = cloudmersive_nlp_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY

Finally, we can now bring in the callback function:

# create an instance of the API class
api_instance = cloudmersive_nlp_api_client.AnalyticsApi(cloudmersive_nlp_api_client.ApiClient(configuration))
input = cloudmersive_nlp_api_client.ProfanityAnalysisRequest() # ProfanityAnalysisRequest | Input profanity analysis request
# Perform Profanity and Obscene Language Analysis and Detection on Text
api_response = api_instance.analytics_profanity(input)
except ApiException as e:
print("Exception when calling AnalyticsApi->analytics_profanity: %s\n" % e)




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.