A python client for the PurgoMalum profanity filter web service
Project description
This is a Python client for the PurgoMalum web service.
Installation
pip install purgomalum
or
python setup.py install
Usage
To use the basic filtering you can call the contains_profanity or the retrieve_filtered_text methods from the client:
>>> from purgo_malum import client >>> client.contains_profanity('You are an @a$$hole') True >>> client.retrieve_filtered_text('You are an @a$$hole') u'You are an ********'
The client functions also support adding words to the profanity list, setting your own filter text, and setting your own filter characters:
>>> from purgo_malum import client >>> client.contains_profanity('You are a good friend', add='you') True >>> client.retrieve_filtered_text('You are a good friend', add='you,are', fill_text='[filtered]') u'[filtered] [filtered] a good friend' >>> client.retrieve_filtered_text('You are a good friend', add='you,are', fill_char='|') u'||| ||| a good friend'
You can also get the raw data that the PurgoMalum API returns by calling the raw version of the APIs:
>>> from purgo_malum import client >>> client.retrieve_filtered_text_raw('You are an @a$$hole', 'json') {u'result': u'You are an ********'} >>> client.retrieve_filtered_text_raw('You are an @a$$hole', 'plain') u'You are an ********' >>> client.retrieve_filtered_text_raw('You are an @a$$hole', 'xml') u'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><PurgoMalum xmlns="http://www.purgomalum.com"><result>You are an ********</result></PurgoMalum>'
This can be helpful in the event that the API changes and/or you feel you can use the raw data in some manner.
You can also see the URL that is created for a specific request by using the build_url method (mainly helpful for testing):
>>> client.build_url('test text', 'json', add='test', fill_text='[filtered]') u'https://www.purgomalum.com/service/json?text=test+text&add=test&fill_text=%5Bfiltered%5D'
Testing
Tests have been for python 2.7 and python 3 using pytest. The unit tests do call the actual PurgoMalum production API in order to test against potential API changes.
Before running tests make sure to install pytest, pytest-cov, pytest-mock, and mock (already included in requirements.txt).
To execute the tests and generate a code coverage report run the following:
pytest --cov-report term-missing --cov=purgo_malum/
You should see:
Name Stmts Miss Cover Missing ------------------------------------------------------- purgo_malum/__init__.py 0 0 100% purgo_malum/client.py 54 0 100% ------------------------------------------------------- TOTAL 54 0 100%
Miscellaneous
This is my first offering to the open source community. If you see any issues with this client library and/or potential improvements please let me know and I will make the necessary updates.
Donation
If this is helpful to you in any please consider a small donation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file PurgoMalum-1.0.3.tar.gz
.
File metadata
- Download URL: PurgoMalum-1.0.3.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
0addb2d753f2f5af0a1d73578ccbe049a176bc1d96e3c21877dba96df86fbc5d
|
|
MD5 |
70e35279a9ad7621026fd333d76829af
|
|
BLAKE2b-256 |
bab69feb9f7101509b8aae0ec928bd5de0534ce591a1fd87b2851152a50f03fa
|