python-disposable 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ # Virtual environments
2
+ .venv/
3
+ venv/
4
+ env/
5
+ ENV/
6
+
7
+ # Build artifacts
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ *.egg
12
+
13
+ # Python cache
14
+ __pycache__/
15
+ *.py[cod]
16
+ *.pyo
17
+ *.pyd
18
+ .Python
19
+
20
+ # Distribution / packaging
21
+ *.whl
22
+ *.tar.gz
23
+ MANIFEST
24
+
25
+ # Testing
26
+ .pytest_cache/
27
+ .coverage
28
+ htmlcov/
29
+ .tox/
30
+
31
+ # IDE
32
+ .idea/
33
+ .vscode/
34
+ *.swp
35
+ *.swo
36
+
37
+ # OS
38
+ .DS_Store
39
+ Thumbs.db
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pescheck B.V.
4
+ Copyright (c) 2017 Andrei Simionescu
5
+ Copyright (c) 2017 Stefan Meinecke, greenSec GmbH
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-disposable
3
+ Version: 0.0.1
4
+ Summary: Check if an email address or domain belongs to a disposable/temporary email service. Bundles 72k+ domains from disposable/disposable-email-domains.
5
+ Project-URL: Source, https://github.com/disposable/disposable-email-domains
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Keywords: disposable,email,spam,validation
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Communications :: Email
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.9
20
+ Provides-Extra: test
21
+ Requires-Dist: pytest>=7; extra == 'test'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # python-disposable
25
+
26
+ A Python package to check if an email address or domain belongs to a disposable/temporary email service.
27
+
28
+ Bundles **72,000+ domains** from [disposable/disposable-email-domains](https://github.com/disposable/disposable-email-domains), updated daily.
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install disposable-email-check
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ```python
39
+ from disposable_email import is_disposable, is_valid, domain_count
40
+
41
+ # Check by email address
42
+ is_disposable("user@mailinator.com") # True
43
+ is_disposable("user@gmail.com") # False
44
+
45
+ # Check by domain only
46
+ is_disposable("guerrillamail.com") # True
47
+
48
+ # Inverse check
49
+ is_valid("user@gmail.com") # True
50
+ is_valid("user@10minutemail.com") # False
51
+
52
+ # How many domains are bundled?
53
+ domain_count() # 72170
54
+ ```
55
+
56
+ ## Django example
57
+
58
+ ```python
59
+ from django import forms
60
+ from disposable_email import is_disposable
61
+
62
+ class RegisterForm(forms.Form):
63
+ email = forms.EmailField()
64
+
65
+ def clean_email(self):
66
+ email = self.cleaned_data["email"]
67
+ if is_disposable(email):
68
+ raise forms.ValidationError("Disposable email addresses are not allowed.")
69
+ return email
70
+ ```
71
+
72
+ ## Updating the domain list
73
+
74
+ The bundled `domains.txt` is sourced from [disposable/disposable-email-domains](https://github.com/disposable/disposable-email-domains) and updated with each package release.
75
+
76
+ To update manually, run:
77
+
78
+ ```bash
79
+ curl -sL https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.txt \
80
+ -o disposable_email/domains.txt
81
+ ```
82
+
83
+ Then bump the version in `pyproject.toml` and re-publish.
@@ -0,0 +1,60 @@
1
+ # python-disposable
2
+
3
+ A Python package to check if an email address or domain belongs to a disposable/temporary email service.
4
+
5
+ Bundles **72,000+ domains** from [disposable/disposable-email-domains](https://github.com/disposable/disposable-email-domains), updated daily.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install disposable-email-check
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ from disposable_email import is_disposable, is_valid, domain_count
17
+
18
+ # Check by email address
19
+ is_disposable("user@mailinator.com") # True
20
+ is_disposable("user@gmail.com") # False
21
+
22
+ # Check by domain only
23
+ is_disposable("guerrillamail.com") # True
24
+
25
+ # Inverse check
26
+ is_valid("user@gmail.com") # True
27
+ is_valid("user@10minutemail.com") # False
28
+
29
+ # How many domains are bundled?
30
+ domain_count() # 72170
31
+ ```
32
+
33
+ ## Django example
34
+
35
+ ```python
36
+ from django import forms
37
+ from disposable_email import is_disposable
38
+
39
+ class RegisterForm(forms.Form):
40
+ email = forms.EmailField()
41
+
42
+ def clean_email(self):
43
+ email = self.cleaned_data["email"]
44
+ if is_disposable(email):
45
+ raise forms.ValidationError("Disposable email addresses are not allowed.")
46
+ return email
47
+ ```
48
+
49
+ ## Updating the domain list
50
+
51
+ The bundled `domains.txt` is sourced from [disposable/disposable-email-domains](https://github.com/disposable/disposable-email-domains) and updated with each package release.
52
+
53
+ To update manually, run:
54
+
55
+ ```bash
56
+ curl -sL https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.txt \
57
+ -o disposable_email/domains.txt
58
+ ```
59
+
60
+ Then bump the version in `pyproject.toml` and re-publish.
@@ -0,0 +1,80 @@
1
+ from __future__ import annotations
2
+
3
+ from importlib.resources import files
4
+ from typing import Optional
5
+
6
+ _domains: Optional[frozenset[str]] = None
7
+ _domains_strict: Optional[frozenset[str]] = None
8
+
9
+
10
+ def _load(strict: bool = False) -> frozenset[str]:
11
+ global _domains, _domains_strict
12
+ if strict:
13
+ if _domains_strict is None:
14
+ data = files("disposable_email").joinpath("domains_strict.txt").read_text(encoding="utf-8")
15
+ _domains_strict = frozenset(line.strip().lower() for line in data.splitlines() if line.strip())
16
+ return _domains_strict
17
+ else:
18
+ if _domains is None:
19
+ data = files("disposable_email").joinpath("domains.txt").read_text(encoding="utf-8")
20
+ _domains = frozenset(line.strip().lower() for line in data.splitlines() if line.strip())
21
+ return _domains
22
+
23
+
24
+ def _extract_domain(email_or_domain: str) -> str:
25
+ """Extract and normalize domain, stripping subdomains if needed."""
26
+ domain = email_or_domain.split("@")[-1].strip().lower()
27
+ return domain
28
+
29
+
30
+ def _is_disposable_domain(domain: str, strict: bool = False) -> bool:
31
+ """Check domain and progressively strip subdomains until a match is found."""
32
+ domains = _load(strict)
33
+ parts = domain.split(".")
34
+ # Check from full domain down to second-level domain (e.g. a.b.c.com -> b.c.com -> c.com)
35
+ for i in range(len(parts) - 1):
36
+ candidate = ".".join(parts[i:])
37
+ if candidate in domains:
38
+ return True
39
+ return False
40
+
41
+
42
+ def is_disposable(email_or_domain: str, strict: bool = False) -> bool:
43
+ """Return True if the email address or domain is a known disposable/temporary email service.
44
+
45
+ Args:
46
+ email_or_domain: An email address (user@example.com) or bare domain (example.com).
47
+ strict: If True, also flags greylisted domains (anonymous signup services).
48
+ """
49
+ domain = _extract_domain(email_or_domain)
50
+ if not domain:
51
+ return False
52
+ return _is_disposable_domain(domain, strict=strict)
53
+
54
+
55
+ def is_valid(email_or_domain: str, strict: bool = False) -> bool:
56
+ """Return True if the email address or domain is NOT a known disposable/temporary email service.
57
+
58
+ Args:
59
+ email_or_domain: An email address (user@example.com) or bare domain (example.com).
60
+ strict: If True, also flags greylisted domains (anonymous signup services).
61
+ """
62
+ return not is_disposable(email_or_domain, strict=strict)
63
+
64
+
65
+ def get_domains(strict: bool = False) -> frozenset[str]:
66
+ """Return the full set of known disposable domains.
67
+
68
+ Args:
69
+ strict: If True, returns the strict list (includes greylisted domains).
70
+ """
71
+ return _load(strict)
72
+
73
+
74
+ def domain_count(strict: bool = False) -> int:
75
+ """Return the number of known disposable domains in the bundled list.
76
+
77
+ Args:
78
+ strict: If True, returns the count for the strict list.
79
+ """
80
+ return len(_load(strict))
@@ -0,0 +1,34 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
12
+
13
+ TYPE_CHECKING = False
14
+ if TYPE_CHECKING:
15
+ from typing import Tuple
16
+ from typing import Union
17
+
18
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
20
+ else:
21
+ VERSION_TUPLE = object
22
+ COMMIT_ID = object
23
+
24
+ version: str
25
+ __version__: str
26
+ __version_tuple__: VERSION_TUPLE
27
+ version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
30
+
31
+ __version__ = version = '0.0.1'
32
+ __version_tuple__ = version_tuple = (0, 0, 1)
33
+
34
+ __commit_id__ = commit_id = None