Skip to content

Commit 004d8e0

Browse files
committed
v0.1.1
0 parents  commit 004d8e0

8 files changed

Lines changed: 254 additions & 0 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build
2+
dist
3+
**/__pycache__
4+
abstract_python_email_validation.egg-info
5+
dev_test.py
6+
.vscode
7+
*.history

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Abstract
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# AbstractAPI python-email-validation library
2+
3+
Integrate the powerful [email validation API from Abstract](https://www.abstractapi.com/email-verification-validation-api) in your Python project in a few lines of code.
4+
5+
Abstract's Email Validation and Verification API is a fast, lightweight, modern, and RESTful JSON API for determining the validity and other details of email addresses.
6+
7+
It's very simple to use: you only need to submit your API key and an email address, and the API will respond an assessment of its validity, as well as additional details like quality score if it's a disposable email, a catchall address, and more.
8+
9+
Validating and verifying email addresses is a critical step to reducing the chances of low-quality data and fraudulent or risky users in your website or application.
10+
11+
# Documentation
12+
13+
## Supported Python Versions
14+
15+
This library supports the **Python version 3.6** and higher.
16+
17+
## Installation
18+
19+
You can install **python-email-validation** via PyPi or by downloading the source.
20+
21+
### Via PyPi:
22+
23+
**python-email-validation** is available on PyPi as the
24+
[`abstract-python-email-validation`](https://pypi.org/project/abstract-python-email-validation/) package:
25+
26+
```bash
27+
pip install abstract-python-email-validation
28+
```
29+
30+
## API key
31+
32+
Get your API key for free and without hassle from the [Abstact website](https://app.abstractapi.com/users/signup?target=/api/email-validation/pricing/select).
33+
34+
## Quickstart
35+
36+
### Verify email
37+
38+
```python
39+
# Verify email using Abstract's Email Validation and Verification API and Python
40+
from python_email_validation import AbstractEmailValidation
41+
42+
EMAIL_VAL_API_KEY = "YYYYYY"; # Get your API Key from https://app.abstractapi.com/api/email-validation/documentation
43+
44+
AbstractEmailValidation.configure(EMAIL_VAL_API_KEY)
45+
AbstractEmailValidation.verify("contact.email@gmail.com")
46+
```
47+
48+
## API response
49+
50+
The API response is returned in a `EmailValidationData` object.
51+
52+
| PARAMETER | TYPE | DETAILS |
53+
| - | - | - |
54+
| email | String | The value for "email" that was entered into the request. |
55+
| auto_correct | String | If a typo has been detected then this parameter returns a suggestion of the correct email (e.g., johnsmith@gmial.com => johnsmith@gmail.com). If no typo is detected then this is empty. |
56+
| deliverability | String | Abstract's evaluation of the deliverability of the email. Possible values are: DELIVERABLE, UNDELIVERABLE, RISKY, and UNKNOWN |
57+
| quality_score | Number | An internal decimal score between 0.01 and 0.99 reflecting Abstract's confidence in the quality and deliverability of the submitted email. |
58+
| is_valid_format | Boolean | Is true if the email follows the format of "address @ domain . TLD". If any of those elements are missing or if they contain extra or incorrect special characters, then it returns false. |
59+
| is_free_email | Boolean | Is true if the email's domain is found among Abstract's list of free email providers (e.g., Gmail, Yahoo, etc). |
60+
| is_disposable_email | Boolean | Is true if the email's domain is found among Abstract's list of disposable email providers (e.g., Mailinator, Yopmail, etc). |
61+
| is_role_email | Boolean | Is true if the email's local part (e.g., the "to" part) appears to be for a role rather than individual. Examples of this include "team@", "sales@", info@", etc. |
62+
| is_catchall_email | Boolean | Is true if the domain is configured to catch all email. |
63+
| is_mx_found | Boolean | Is true if MX Records for the domain can be found. Only available on paid plans. Will return null and UNKNOWN on free plans. |
64+
| is_smtp_valid | Boolean | Is true is the SMTP check of the domain was successful. Only available on paid plans. Will return null and UNKNOWN on free plans. |
65+
66+
## Detailed documentation
67+
68+
You will find additional information and request examples in the [Abstract help page](https://app.abstractapi.com/api/email-validation/documentation).
69+
70+
## Getting help
71+
72+
If you need help installing or using the library, please contact [Abstract's Support](https://app.abstractapi.com/api/email-validation/support).
73+
74+
For bug report and feature suggestion, please use [this repository issues page](https://github.com/abstractapi/python-email-validation/issues).
75+
76+
# Contribution
77+
78+
Contributions are always welcome, as they improve the quality of the libraries we provide to the community.
79+
80+
Please provide your changes covered by the appropriate unit tests, and post them in the [pull requests page](https://github.com/abstractapi/python-email-validation/pulls).
81+
82+
## Composer
83+
84+
To work on the source code, you need to install composer on your local computer. At the time of writing, the latest version of composer is v2.0.12. The installation instructions can be found here: https://getcomposer.org/download/.
85+
86+
## Setup
87+
88+
To install the requirements, run:
89+
90+
```bash
91+
python3 setup.py install --user
92+
```
93+
94+
Once you implementer all your changes and the unit tests, run the following command to run the tests:
95+
96+
```bash
97+
EMAIL_VAL_API_KEY=YYYYYY python3 tests/test_python_email_validation.py
98+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .python_email_validation import AbstractEmailValidation
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from python_core import HttpEndpoint
2+
from collections import namedtuple
3+
4+
class AbstractEmailValidation:
5+
api_key = None
6+
http_endpoint = HttpEndpoint(
7+
endpoint_subdomain='emailvalidation',
8+
global_req_params={
9+
'lang' : 'python'
10+
}
11+
)
12+
13+
@staticmethod
14+
def configure(api_key):
15+
AbstractEmailValidation.api_key = api_key
16+
17+
@staticmethod
18+
def verify(email):
19+
20+
if AbstractEmailValidation.api_key is None:
21+
exception_type = "APINotConfiguredException"
22+
exception_msg = "Can't use the endpoint unless it's configured, use configure(api_key)"
23+
raise Exception(
24+
"[{}] : {}".format(exception_type, exception_msg)
25+
)
26+
27+
try:
28+
req_params = {
29+
"api_key" : AbstractEmailValidation.api_key,
30+
"email" : email
31+
}
32+
response = AbstractEmailValidation.http_endpoint.get(
33+
req_params=req_params
34+
)
35+
# Convert the dict to an object
36+
for key in response:
37+
if (type(response[key]) == dict):
38+
# dict holding only {value, text}
39+
if "value" in response[key]:
40+
response[key] = response[key]["value"]
41+
# embedded dict, convert to object
42+
else:
43+
EmbeddedObject = namedtuple('EmbeddedObject', response[key])
44+
embedded_obj = EmbeddedObject(**response[key])
45+
response[key] = embedded_obj
46+
ResponseObject = namedtuple('ResponseObject', response.keys())
47+
response_obj = ResponseObject(**response)
48+
return response_obj
49+
50+
except Exception as e:
51+
# HttpEndpoint has expressive exceptions
52+
raise SystemExit(e)

requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
certifi==2020.12.5
2+
chardet==4.0.0
3+
idna==2.10
4+
plotly==4.14.3
5+
requests==2.25.1
6+
urllib3==1.26.4
7+
wincertstore==0.2
8+
python-dotenv==0.17.0
9+
abstract_python_core==0.1.0

setup.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from setuptools import setup, find_packages
2+
3+
try: # for pip >= 10
4+
from pip._internal.req import parse_requirements
5+
except ImportError: # for pip <= 9.0.3
6+
from pip.req import parse_requirements
7+
8+
# Set the library's long description to the repo's README.md
9+
with open('README.md', 'r') as readme_file:
10+
readme = readme_file.read()
11+
12+
with open('requirements.txt') as f:
13+
required = f.read().splitlines()
14+
15+
requirements = required
16+
17+
setup(
18+
name='abstract_python_email_validation',
19+
version='0.1.1',
20+
author='Benjamin Bouchet',
21+
author_email='libraries@abstractapi.com',
22+
description="AbstractEmailValidation - Wrapper to quickly start using the powerful AbstractAPI's email validation service in your projects.",
23+
long_description=readme,
24+
long_description_content_type='text/markdown',
25+
url='https://github.com/abstractapi/python-email-validation',
26+
packages=find_packages(),
27+
install_requires=requirements,
28+
classifiers=[
29+
'Programming Language :: Python :: 3.6',
30+
'Intended Audience :: Developers',
31+
'License :: OSI Approved :: MIT License',
32+
],
33+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import unittest
2+
import os, sys
3+
4+
from python_email_validation import AbstractEmailValidation
5+
from dotenv import load_dotenv
6+
7+
load_dotenv()
8+
9+
EMAIL_VAL_API_KEY = os.getenv('EMAIL_VAL_API_KEY')
10+
11+
12+
class TestAbstractEmailValidation(unittest.TestCase):
13+
def __init__(self, *args, **kwargs):
14+
15+
super(TestAbstractEmailValidation, self).__init__(*args, **kwargs)
16+
self.api = AbstractEmailValidation()
17+
18+
def test_no_config(self):
19+
20+
with self.assertRaises(Exception):
21+
# tests aren't always run in order, so make sure to
22+
# clear api_key
23+
AbstractEmailValidation.api_key = None
24+
AbstractEmailValidation.verify("contact.email@gmail.com")
25+
26+
def test_config(self):
27+
28+
AbstractEmailValidation.configure(EMAIL_VAL_API_KEY)
29+
AbstractEmailValidation.verify("contact.email@gmail.com")
30+
31+
32+
if __name__ == '__main__':
33+
unittest.main()

0 commit comments

Comments
 (0)