Metadata-Version: 2.4
Name: ipatel
Version: 0.1.1
Summary: A Python IP enrichment library
Author-email: Chethan Patel <chethanpatel100@gmail.com>
Project-URL: Homepage, https://github.com/Chethanpatel/ipatel
Project-URL: Documentation, https://Chethanpatel.github.io/ipatel/
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rich
Dynamic: license-file

# 🌐 `ipatel` — IP Enrichment Library & CLI

---

## 🔍 What is `ipatel`?

**`ipatel`** is a lightweight Python library and CLI tool that enriches IP addresses and ASNs with useful metadata:

* 🛰️ **ASN (Autonomous System Number)**
* 🏢 **AS Owner / Organization**
* 🌎 **Country Code**
* 🧭 **IP Type** — Public / Private / Reserved
* 📶 **IP Ranges for ASN**

---

## ✨ Key Features

* ⚡ Fast and works **offline** after initial DB download
* 🔄 Auto-updates the enrichment database
* 💻 Simple and intuitive **Python API & CLI**
* 🧪 Fully tested, clean, and modular codebase
* 📦 Easy to install via `pip`

---

## 🚀 Quickstart Guide

### 🔧 Installation

```bash
pip install ipatel
```

---

## 🧩 Basic Setup

```python
import ipatel as ip

test_ip = "8.8.8.8"
test_asn = 15169
```

---

## 🌐 IP Enrichment

### 🔹 Enrich IP with full metadata

```python
ip.enrich_ip("8.8.8.8")
```

**Returns:**

```python
{
    'ip': '8.8.8.8',
    'asn': 15169,
    'country_code': 'US',
    'owner': 'GOOGLE',
    'ip_type': 'Public'
}
```

---

## 🧠 ASN Lookup Functions

| Function                        | Description               | Example                           |
| ------------------------------- | ------------------------- | --------------------------------- |
| `ip.get_record(ip)`             | Full ASN record           | `ip.get_record("8.8.8.8")`        |
| `ip.get_asn(ip)`                | Get ASN only              | `15169`                           |
| `ip.get_country_code(ip)`       | Get country code          | `"US"`                            |
| `ip.get_owner(ip)`              | Get AS owner              | `"GOOGLE"`                        |
| `ip.get_ip_ranges_for_asn(asn)` | List of IP ranges for ASN | `ip.get_ip_ranges_for_asn(15169)` |

---

## 🛠️ Utilities

| Function                      | Description    | Output       |
| ----------------------------- | -------------- | ------------ |
| `ip.ip_to_int("8.8.8.8")`     | IP → Integer   | `134744072`  |
| `ip.int_to_ip(134744072)`     | Integer → IP   | `"8.8.8.8"`  |
| `ip.get_ip_type("127.0.0.1")` | Detect IP type | `"Loopback"` |

---

## 🔄 Database Management

| Task               | Function                  | Description                         |
| ------------------ | ------------------------- | ----------------------------------- |
| 📥 Download DB     | `ip.download_ip2asn_db()` | Manually fetch latest DB            |
| 🔁 Ensure Fresh DB | `ip.ensure_ip2asn_db()`   | Checks & auto-downloads if outdated |

---

## 🧪 Test Script

```python
def run_tests():
    ip.ensure_ip2asn_db()
    print(ip.enrich_ip("8.8.8.8"))

if __name__ == "__main__":
    run_tests()
```

---

## 📝 Notes

* IPv4 only (IPv6 support planned)
* Handles loopback, private, and reserved IPs safely
* CLI and API produce consistent outputs

---

## 📚 Learn More

* 📌 [CLI Usage](docs/cli.md)
* 🧾 [Detailed API Reference](docs/api.md)
* 🔁 [Database Update Guide](docs/update.md)
* 📂 [GitHub Repository](https://github.com/Chethanpatel/ipatel)

---
