Metadata-Version: 2.4
Name: grip-client
Version: 0.1.2
Summary: Python client for the GRIP API
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.31
Provides-Extra: cachetools
Requires-Dist: cachetools>=5; extra == "cachetools"
Provides-Extra: redis
Requires-Dist: redis>=5; extra == "redis"
Provides-Extra: mmdb
Requires-Dist: filelock>=3; extra == "mmdb"
Requires-Dist: maxminddb>=2; extra == "mmdb"
Requires-Dist: pycountry>=24; extra == "mmdb"
Provides-Extra: cache
Requires-Dist: cachetools>=5; extra == "cache"
Requires-Dist: redis>=5; extra == "cache"

# grip-client

## Python client for the GRIP API.

```python
from grip_client.rest import GRIPClient

client = GRIPClient(token="token", timeout=5.0)
response = client.response_ip("8.8.8.8")

print(response.ip)
print(response.country_iso)
```

#### Optional in-memory caching:

```python
from grip_client.rest import GRIPClient, CachetoolsCache

client = GRIPClient(
    token="token",
    cache=CachetoolsCache(ttl=300, maxsize=1024),
)
response = client.response_ip("8.8.8.8")
```

#### Optional Redis caching:

```python
from grip_client.rest import GRIPClient, RedisCache

client = GRIPClient(
    token="token",
    cache=RedisCache.from_url("redis://localhost:6379/0", ttl=300),
)
response = client.response_ip("8.8.8.8")
```

## MMDB local lookup:

Features:

- MMDB downloads use the gzipped asset by default, and cache the decompressed `.mmdb` on disk.
- Files are updated asynchronously every hour.
- Reader is thread-safe

```python
from grip_client.mmdb import GRIPMMDBClient

mmdb = GRIPMMDBClient(token="token")
res = mmdb.lookup("8.8.8.8")

print(
    f"{res.asn.network_operator=}, "
    f"{res.country.country_iso=}, "
    f"{res.anonymous.is_anonymous=}"
)

```

#### Individual MMDBs can be used directly:

```python
from grip_client.mmdb import GRIPMMDB, GRIPMMDBKind

anonymous = GRIPMMDB(
    kind=GRIPMMDBKind.GRIP_ANONYMOUS,
    max_age_seconds=3600,
    token="token"
)

if anonymous.is_anonymous("8.8.8.8"):
    print("skip API lookup")
```
