Python SDK: local install and lookup
Python 3.10+. Extract the source and run the local installation inside your virtual environment, using the directory containing pyproject.toml.
python -m pip install ./path/to/extracted-sdk
# Python application:
import os
from origooo import Client, ApiError
client = Client(os.environ['ORIGOOO_API_KEY'],
base_url='https://orig.ooo', timeout=2.0,
ttl=300, retries=1)
try:
result = client.lookup('8.8.8.8')
country = result.country_code
except ApiError as error:
status = error.status
# Apply your unavailable-data fallback.Location exposes ip, country_code, city, source_id and raw. Invalid input raises ValueError. ApiError exposes status and code. WSGIMiddleware and ASGIMiddleware support explicit country policies.
Coverage, caching and failures
The source SDKs expose single-IP lookup and country-policy helpers. Use direct HTTP for batch, ASN, comparisons and metadata. A 404 becomes an empty country result. A 429 surfaces as an exception; handle it with bounded backoff in your application. Local SDK cache hits make no HTTP request. API-side cache hits remain billable.
Set the API origin explicitly to https://orig.ooo. Resolve a visitor IP using your configured trusted-proxy rules; a backend /v1/ip/me request identifies the backend server.
Apply a country policy
The following code belongs before protected content. It uses the actual client/policy interfaces in the downloadable SDK. The full guide includes installation assumptions, proxy handling and unknown-country behaviour.
import os
from origooo import Client, Policy, WSGIMiddleware
client = Client(os.environ['ORIGOOO_API_KEY'], base_url='https://orig.ooo')
policy = Policy(blocked=frozenset({'US', 'GB'}), unknown='deny')
def protected_app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [b'Allowed content']
# Put the middleware before your existing WSGI application.
app = WSGIMiddleware(protected_app, client, policy, trusted_proxies=[])
# ASGI applications can use ASGIMiddleware with the same client/policy.