Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 1.98 KB

README.rst

File metadata and controls

65 lines (46 loc) · 1.98 KB

pymailcheck

Suggest corrections to user-misspelled email addresses.

Python port of mailcheck.js.

Installation

$ pip install pymailcheck

Usage

>>> import pymailcheck
>>> pymailcheck.suggest("[email protected]")
{'domain': 'example.com', 'full': '[email protected]', 'address': 'test'}
>>> pymailcheck.suggest("[email protected]")
False

You can override or append the built-in list of domains, top-level domains, and/or second-level domains:

Parameter Defaults Example
domains pymailcheck.DOMAINS yahoo.com
top_level_domains pymailcheck.TOP_LEVEL_DOMAINS yahoo
second_level_domains pymailcheck.SECOND_LEVEL_DOMAINS com
>>> pymailcheck.suggest("[email protected]")
False
>>> custom_domains = ["example.com", "contoso.com"]
>>> pymailcheck.suggest("[email protected]", domains=custom_domains)
{'domain': 'contoso.com', 'full': '[email protected]', 'address': 'test'}
>>> pymailcheck.suggest("[email protected]")
False
>>> custom_domains = pymailcheck.DOMAINS.union(("example.com", "contoso.com"))
>>> pymailcheck.suggest("[email protected]", domains=custom_domains)
{'domain': 'contoso.com', 'full': '[email protected]', 'address': 'test'}
>>> def my_distance_function(s1, s2): ...
>>> # Have a look at `strsim` PyPI package, for example
>>> pymailcheck.suggest("[email protected]", distance_callable=my_distance_function)
{'domain': 'contoso.com', 'full': '[email protected]', 'address': 'test'}

Running Tests

$ python -m unittest discover