From aac48c58173a580d2b40d74b33be3b0b7f1a4cd6 Mon Sep 17 00:00:00 2001 From: Semyon Pupkov Date: Thu, 7 Sep 2023 10:55:39 +0500 Subject: [PATCH] Make dnspython package is optional --- README.md | 6 ++++++ email_validator/deliverability.py | 7 +++++-- setup.cfg | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 72b3b0f..df8f2af 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,12 @@ This package [is on PyPI](https://pypi.org/project/email-validator/), so: pip install email-validator ``` +If deliverability option will be used: + +```sh +pip install email-validator[dns] +``` + (You might need to use `pip3` depending on your local environment.) Quick Start diff --git a/email_validator/deliverability.py b/email_validator/deliverability.py index 4846091..a66e2ee 100644 --- a/email_validator/deliverability.py +++ b/email_validator/deliverability.py @@ -2,8 +2,11 @@ from .exceptions_types import EmailUndeliverableError -import dns.resolver -import dns.exception +try: + import dns.resolver + import dns.exception +except ImportError as e: + raise ImportError('deliverability option requires dnspython, run `pip install email-validator[dns]`') from e def caching_resolver(*, timeout: Optional[int] = None, cache=None): diff --git a/setup.cfg b/setup.cfg index dc97892..4974e72 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,10 +25,13 @@ keywords = email address validator [options] packages = find: install_requires = - dnspython>=2.0.0 # optional if deliverability check isn't needed idna>=2.0.0 python_requires = >=3.7 +[options.extras_require] +# optional if deliverability check isn't needed +dns = dnspython>=2.0.0 + [options.package_data] * = py.typed