checkthatphone 0.1.0__py3-none-any.whl

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,151 @@
1
+ """Official Python client for the CheckThatPhone API.
2
+
3
+ https://checkthatphone.com/docs
4
+
5
+ Zero dependencies — standard library only. Python 3.9+.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import urllib.error
12
+ import urllib.request
13
+ from typing import Any, Optional
14
+
15
+ __version__ = "0.1.0"
16
+ __all__ = ["CheckThatPhone", "CheckThatPhoneError", "LookupResult"]
17
+
18
+ _DEFAULT_BASE_URL = "https://api.checkthatphone.com"
19
+
20
+
21
+ class CheckThatPhoneError(Exception):
22
+ """Raised for non-2xx API responses.
23
+
24
+ Attributes:
25
+ status: HTTP status (400 invalid input, 401 bad key, 402 quota,
26
+ 429 rate limit, 502 upstream).
27
+ code: machine-readable error string from the API.
28
+ detail: human-readable detail, when the API provides one.
29
+ """
30
+
31
+ def __init__(self, status: int, code: str, detail: Optional[str] = None):
32
+ super().__init__(f"{code}: {detail}" if detail else code)
33
+ self.status = status
34
+ self.code = code
35
+ self.detail = detail
36
+
37
+ @property
38
+ def retryable(self) -> bool:
39
+ """True when retrying the identical request may succeed."""
40
+ return self.status == 429 or self.status >= 500
41
+
42
+
43
+ class LookupResult:
44
+ """Envelope for one lookup.
45
+
46
+ Attributes:
47
+ success: whether the lookup succeeded.
48
+ credits_used: credits this call drew from your plan.
49
+ data: response fields (string-valued; add-on fields present only when
50
+ the matching flag was sent). Full reference:
51
+ https://checkthatphone.com/docs
52
+ """
53
+
54
+ def __init__(self, success: bool, credits_used: int, data: dict[str, Any]):
55
+ self.success = success
56
+ self.credits_used = credits_used
57
+ self.data = data
58
+
59
+ def __repr__(self) -> str: # pragma: no cover
60
+ return (
61
+ f"LookupResult(success={self.success}, credits_used={self.credits_used}, "
62
+ f"data_keys={sorted(self.data)!r})"
63
+ )
64
+
65
+
66
+ class CheckThatPhone:
67
+ """CheckThatPhone API client.
68
+
69
+ Usage::
70
+
71
+ from checkthatphone import CheckThatPhone
72
+
73
+ client = CheckThatPhone(api_key="ctp_live_...")
74
+ result = client.lookup("8182925409", litigator_filter=True, dnc_other=True)
75
+ if result.data.get("litigator") == "true":
76
+ ...
77
+ """
78
+
79
+ def __init__(self, api_key: str, *, base_url: str = _DEFAULT_BASE_URL, timeout: float = 15.0):
80
+ if not api_key or not isinstance(api_key, str):
81
+ raise ValueError(
82
+ "api_key is required — create one at https://checkthatphone.com/dashboard/keys"
83
+ )
84
+ self._api_key = api_key
85
+ self._base_url = base_url.rstrip("/")
86
+ self._timeout = timeout
87
+
88
+ def lookup(
89
+ self,
90
+ phone: str,
91
+ *,
92
+ ip: Optional[str] = None,
93
+ litigator_filter: bool = False,
94
+ landline_sms_lookup: bool = False,
95
+ dnc_other: bool = False,
96
+ ) -> LookupResult:
97
+ """Validate one US/Canada phone number.
98
+
99
+ Args:
100
+ phone: 10-digit number (11-digit with leading 1 also accepted);
101
+ non-digits are ignored, so "(818) 292-5409" is fine.
102
+ ip: IPv4/IPv6 of the number's owner — enables precise GeoIP
103
+ and timezone data.
104
+ litigator_filter: TCPA litigator scrub (+1 credit).
105
+ landline_sms_lookup: landline SMS reachability (+1 credit,
106
+ charged only when the number is a landline).
107
+ dnc_other: state DNC & complainers scrub (free).
108
+
109
+ Raises:
110
+ CheckThatPhoneError: for any non-2xx API response.
111
+ """
112
+ body: dict[str, Any] = {"phone": phone}
113
+ if ip:
114
+ body["ip"] = ip
115
+ if litigator_filter:
116
+ body["litigatorFilter"] = True
117
+ if landline_sms_lookup:
118
+ body["landlineSmsLookup"] = True
119
+ if dnc_other:
120
+ body["dncOther"] = True
121
+
122
+ req = urllib.request.Request(
123
+ f"{self._base_url}/v1/lookup",
124
+ data=json.dumps(body).encode(),
125
+ headers={
126
+ "Authorization": f"Bearer {self._api_key}",
127
+ "Content-Type": "application/json",
128
+ "User-Agent": f"checkthatphone-python/{__version__}",
129
+ },
130
+ method="POST",
131
+ )
132
+
133
+ try:
134
+ with urllib.request.urlopen(req, timeout=self._timeout) as res:
135
+ payload = json.loads(res.read().decode() or "{}")
136
+ except urllib.error.HTTPError as e:
137
+ try:
138
+ err = json.loads(e.read().decode() or "{}")
139
+ except (ValueError, OSError):
140
+ err = {}
141
+ raise CheckThatPhoneError(
142
+ e.code,
143
+ err.get("error") or f"HTTP {e.code}",
144
+ err.get("detail"),
145
+ ) from None
146
+
147
+ return LookupResult(
148
+ success=payload.get("success") is True,
149
+ credits_used=payload.get("credits_used") or 0,
150
+ data=payload.get("data") or {},
151
+ )
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.5
2
+ Name: checkthatphone
3
+ Version: 0.1.0
4
+ Summary: Official Python client for the CheckThatPhone phone validation API — US & Canada carrier lookup, line type, TCPA litigator and state DNC screening
5
+ Project-URL: Homepage, https://checkthatphone.com
6
+ Project-URL: Documentation, https://checkthatphone.com/docs
7
+ Project-URL: Repository, https://github.com/CheckThatPhone/checkthatphone-python
8
+ Author-email: CheckThatPhone <hello@checkthatphone.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: carrier-lookup,dnc,litigator,nanp,phone-number,phone-validation,sms,tcpa
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Communications :: Telephony
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+
19
+ # checkthatphone
20
+
21
+ Official Python client for the [CheckThatPhone](https://checkthatphone.com) phone validation API. Validate US and Canadian phone numbers in real time: carrier and line type from live carrier data, portability and deliverability, GeoIP and timezone, plus optional TCPA litigator screening and a free state do-not-call scrub — one call, one credit.
22
+
23
+ Zero dependencies (standard library only). Python 3.9+.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install checkthatphone
29
+ ```
30
+
31
+ ## Quick start
32
+
33
+ ```python
34
+ import os
35
+ from checkthatphone import CheckThatPhone
36
+
37
+ client = CheckThatPhone(api_key=os.environ["CHECKTHATPHONE_API_KEY"])
38
+
39
+ result = client.lookup("8182925409")
40
+ print(result.data["nanpType"]) # "mobile"
41
+ print(result.data["dipCarrier"]) # "AT&T"
42
+ print(result.data["deliverable"]) # "true"
43
+ print(result.credits_used) # 1
44
+ ```
45
+
46
+ Get an API key at [checkthatphone.com](https://checkthatphone.com) — the free tier includes 500 lookups per month.
47
+
48
+ ## TCPA litigator screening
49
+
50
+ Flag known serial TCPA plaintiffs before you call or text (+1 credit):
51
+
52
+ ```python
53
+ result = client.lookup("8182925409", litigator_filter=True)
54
+ if result.data.get("litigator") == "true":
55
+ # result.data["litigator_type"]: "litigator" | "plaintiff" | "agitator"
56
+ suppress(result.data["subscriber"])
57
+ ```
58
+
59
+ ## State DNC scrub (free)
60
+
61
+ Screen state do-not-call registries (40 states) and a national complainer list at no extra credit:
62
+
63
+ ```python
64
+ result = client.lookup("8182925409", dnc_other=True)
65
+ result.data.get("dncStateResult") # "STATE DNC" or ""
66
+ result.data.get("dncComplainerResult") # "DNC COMPLAINER" or ""
67
+ result.data.get("dncStateCovered") # "false" = state not in the data; don't read "" as clear
68
+ ```
69
+
70
+ ## Landline SMS reachability
71
+
72
+ Some landlines can receive texts. Detect them instead of dropping them (+1 credit, charged only when the number is a landline):
73
+
74
+ ```python
75
+ result = client.lookup("5551234567", landline_sms_lookup=True)
76
+ if result.data.get("dipMessagingEnabled") == "true":
77
+ send_sms(...)
78
+ ```
79
+
80
+ ## GeoIP and timezone
81
+
82
+ Pass the contact's IP for city-level location and the IANA timezone (no extra charge) — useful for TCPA calling-hours compliance:
83
+
84
+ ```python
85
+ result = client.lookup("8182925409", ip="136.38.145.14")
86
+ result.data["timezone"] # "America/Los_Angeles"
87
+ ```
88
+
89
+ ## Errors
90
+
91
+ Non-2xx responses raise `CheckThatPhoneError` with `status`, `code`, `detail`, and a `retryable` hint. Failed and invalid requests are billed 0 credits.
92
+
93
+ ```python
94
+ from checkthatphone import CheckThatPhoneError
95
+
96
+ try:
97
+ client.lookup("not-a-number")
98
+ except CheckThatPhoneError as err:
99
+ if err.retryable:
100
+ retry_later()
101
+ ```
102
+
103
+ ## Full field reference
104
+
105
+ Every response field (carrier DIP, portability/LRN, deactivation, blacklist, and more) is documented at [checkthatphone.com/docs](https://checkthatphone.com/docs).
106
+
107
+ ## License
108
+
109
+ MIT
@@ -0,0 +1,5 @@
1
+ checkthatphone/__init__.py,sha256=3biT7wMRtuM4qTmZvbRAayV_aafSuaIW7cWRTuM5c4Y,4964
2
+ checkthatphone-0.1.0.dist-info/METADATA,sha256=GN-4Ckb3H6GyMRsXLtMlbyI7lmUPxgnW0QEEIrZu_xM,3690
3
+ checkthatphone-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
4
+ checkthatphone-0.1.0.dist-info/licenses/LICENSE,sha256=eJIgu65NX9Cn1Mzw3FI5DFMrgorGKL7iQwp-9SIOXC8,1071
5
+ checkthatphone-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CheckThatPhone
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.