Metadata-Version: 2.5
Name: 1lookup
Version: 0.1.0
Summary: Official Python client for the 1Lookup API: phone validation, carrier and line type, HLR, caller name (CNAM), reverse phone and email lookup, email verification, IP lookup and DNC scrub.
Project-URL: Homepage, https://www.1lookup.io
Project-URL: Documentation, https://app.1lookup.io/api
Project-URL: Pricing, https://www.1lookup.io/pricing
Author: 1Lookup
License-Expression: MIT
License-File: LICENSE
Keywords: 1lookup,api client,caller id,carrier lookup,cnam,dnc,do not call,email validation,email verification,hlr lookup,ip lookup,line type,phone lookup,phone validation,reverse email lookup,reverse phone lookup,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# 1lookup (Python)

Official Python client for the [1Lookup](https://www.1lookup.io) API: phone validation, carrier and line type, HLR lookup, caller name (CNAM), reverse phone and reverse email lookup, email verification, IP lookup and Do Not Call scrub.

- One API key and one shared credit balance for every endpoint.
- Typed results (`TypedDict`) and typed errors; ships `py.typed`.
- Zero dependencies: standard library only. Python 3.9 or newer.

Full API reference: https://app.1lookup.io/api
Pricing: https://www.1lookup.io/pricing

## Install

```bash
pip install 1lookup
```

The package installs as `1lookup` and imports as `onelookup` (a Python module name cannot start with a digit).

Create an API key at https://app.1lookup.io/api-keys and keep it on your server.

```python
import os
from onelookup import OneLookup

client = OneLookup(os.environ["ONELOOKUP_API_KEY"])
```

If you leave out the key, the client reads the `ONELOOKUP_API_KEY` environment variable.

## Examples

### 1. Validate a phone number (line type and carrier)

```python
phone = client.validate_phone("+14155552671")

print(phone["classification"]["line_type"])        # e.g. "MOBILE"
print(phone["classification"]["number_status"])    # e.g. "ACTIVE"
print(phone["insights"]["raw_api_fields"]["network"])  # carrier name
print(phone["insights"]["reachability"]["is_reachable"])
```

### 2. Verify an email address

```python
email = client.verify_email("ada@example.com")

if email["classification"]["deliverability_status"] == "DELIVERABLE":
    pass  # safe to send
print(email["risk_assessment"]["risk_factors"])  # e.g. ["ROLE_BASED_EMAIL"]
```

### 3. HLR lookup (live mobile network status)

```python
hlr = client.hlr_lookup("+447700900123")

print(hlr["classification"]["connectivity_status"])  # CONNECTED, ABSENT, INVALID_MSISDN or UNDETERMINED
print(hlr["insights"]["hlr_result"]["current_carrier"])
```

### 4. Check Do Not Call, then look up the caller name (CNAM)

```python
scrub = client.scrub_phone("+14155552671")

if not scrub["classification"]["doNotCall"] and not scrub["classification"]["litigator"]:
    cnam = client.cnam_lookup("+14155552671")
    if cnam["classification"]["matched"]:
        print(cnam["classification"]["primary_name"])
```

### 5. Look up an IP address

```python
ip = client.lookup_ip("8.8.8.8")

print(ip["insights"]["location"]["country_code"])
print(ip["classification"]["connection_type"])
print(ip["risk_assessment"]["fraud_score"])
```

## Methods

Every lookup method returns the response's `data` object as a `dict`. Results come from a 7-day cache when the same lookup ran recently; pass `bypass_cache=True` to force a fresh lookup (it spends credits even when a cached result exists).

| Method | Endpoint | Returns |
|---|---|---|
| `validate_phone(phone)` | `POST /phone` | Line type, carrier, location, reachability, porting, DNC/DNO flags |
| `carrier_lookup(phone)` | `POST /phone` | Same call as `validate_phone`; carrier name in `insights["raw_api_fields"]["network"]` |
| `line_type(phone)` | `POST /nt-lookup` | Mobile, landline, VoIP or other, plus validity |
| `hlr_lookup(phone)` | `POST /hlr-lookup` | Live subscriber status, roaming state and network |
| `mnp_lookup(phone)` | `POST /mnp-lookup` | The network a number was ported to |
| `reverse_phone(phone, lookup_source=...)` | `POST /reverse-phone-lookup` | Person or business behind a number (`"standard"` or `"premium"`) |
| `cnam_lookup(phone)` | `POST /reverse-phone-lookup` | Caller name from caller ID records (`lookup_source="standard"`) |
| `scrub_phone(phone)` | `POST /phone-scrub` | Do Not Call and known-litigator check |
| `phone_spam(phone)` | `POST /phone-spam` | Spam or fraud history |
| `verify_email(email)` | `POST /email` | Deliverability; disposable, role-based and risky flags |
| `reverse_email(email)` | `POST /reverse-email-append` | Person and company behind an email address |
| `lookup_ip(ip)` | `POST /ip` | Geolocation, connection type, proxy, VPN, Tor and datacenter flags |
| `get_account()` | `GET /account` | Plan, credit balance and usage (spends no credits) |
| `request(method, path, body=None)` | any | Any other endpoint in the [API reference](https://app.1lookup.io/api) |

What each lookup costs: see [pricing](https://www.1lookup.io/pricing).

### Any other endpoint

```python
age = client.request("POST", "/domain-age", {"domain": "example.com"})
```

## Errors and retries

Failed calls raise a subclass of `OneLookupError` with `status`, `code` (the API's error code), `message`, `request_id` and, when the API sends it, `retry_after` in seconds.

```python
from onelookup import AuthenticationError, InsufficientCreditsError, RateLimitError

try:
    client.validate_phone("+14155552671")
except InsufficientCreditsError:
    ...  # 402: out of credits, see https://www.1lookup.io/pricing
except RateLimitError as err:
    ...  # 429: wait err.retry_after seconds
except AuthenticationError:
    ...  # 401: check the API key
```

| Status | Class |
|---|---|
| 400 | `BadRequestError` |
| 401 | `AuthenticationError` |
| 402 | `InsufficientCreditsError` |
| 403 | `PermissionDeniedError` |
| 429 | `RateLimitError` (also has `rate_limit["limit"]`, `["remaining"]`, `["reset"]`) |
| 503 | `ServiceUnavailableError` |
| other 5xx | `ServerError` |
| no answer | `APIConnectionError`, `APITimeoutError` |

The client retries 429 and 503 answers up to 2 times, waiting for `Retry-After`. Nothing else is retried. Change it with `max_retries` (0 turns retries off) and `max_retry_delay` (a `Retry-After` longer than this, in seconds, is raised to you instead of waited on).

```python
client = OneLookup(
    os.environ["ONELOOKUP_API_KEY"],
    timeout=30,          # seconds per request, default 60
    max_retries=2,
    max_retry_delay=20,
)
```

## AI agents

Agents can also call 1Lookup over the hosted MCP server at https://app.1lookup.io/api/mcp instead of REST.

## License

MIT
