Integration Examples
Real-world code examples for common use cases.
Python: Pre-flight check for a LangChain agent
Add Maango as a policy checker before every web fetch in a LangChain tool. The agent won't visit blocked domains.
import httpx
from langchain.tools import tool
MAANGO_KEY = "maango_sk_xxxxx"
async def is_domain_allowed(url: str) -> bool:
"""Check if the domain allows AI access before visiting."""
domain = url.split("//")[-1].split("/")[0].replace("www.", "")
r = await httpx.get(
f"https://api.maango.io/v1/domain/{domain}",
headers={"Authorization": f"Bearer {MAANGO_KEY}"}
)
policy = r.json()
if not policy.get("found"):
return True # Not in registry, proceed with caution
# Block if the domain blocks all AI
if policy["stance"] == "blocks_all_ai":
return False
# Check specific use case
use_cases = policy.get("use_cases", {})
if use_cases.get("inference") == "blocked":
return False
return True
@tool
async def fetch_webpage(url: str) -> str:
"""Fetch a webpage, respecting AI policies."""
if not await is_domain_allowed(url):
return f"Cannot access {url}: domain blocks AI agents."
async with httpx.AsyncClient() as client:
r = await client.get(url, follow_redirects=True)
return r.text[:5000]JavaScript: Check policy in a Node.js agent
A simple wrapper for any Node.js agent that needs to check domain policies.
const MAANGO_KEY = "maango_sk_xxxxx";
async function checkPolicy(url) {
const domain = new URL(url).hostname.replace("www.", "");
const res = await fetch(
`https://api.maango.io/v1/domain/${domain}`,
{ headers: { Authorization: `Bearer ${MAANGO_KEY}` } }
);
if (!res.ok) {
console.warn(`Maango API error: ${res.status}`);
return { allowed: true, reason: "api_error" };
}
const policy = await res.json();
if (!policy.found) {
return { allowed: true, reason: "not_in_registry" };
}
if (policy.stance === "blocks_all_ai") {
return { allowed: false, reason: policy.stance, domain };
}
if (policy.use_cases?.inference === "blocked") {
return { allowed: false, reason: "inference_blocked", domain };
}
return { allowed: true, reason: policy.stance, domain };
}
// Usage
const result = await checkPolicy("https://nytimes.com/article/...");
if (!result.allowed) {
console.log(`Skipping ${result.domain}: ${result.reason}`);
} else {
// Proceed with fetch
}Python: Batch check domains from a list
Loop through a list of URLs, check each domain, and filter out blocked ones.
import httpx
import asyncio
MAANGO_KEY = "maango_sk_xxxxx"
async def batch_check(urls: list[str]) -> dict:
"""Check a list of URLs and categorize by policy."""
allowed = []
blocked = []
unknown = []
async with httpx.AsyncClient() as client:
for url in urls:
domain = url.split("//")[-1].split("/")[0].replace("www.", "")
try:
r = await client.get(
f"https://api.maango.io/v1/domain/{domain}",
headers={"Authorization": f"Bearer {MAANGO_KEY}"}
)
policy = r.json()
if not policy.get("found"):
unknown.append({"url": url, "domain": domain})
elif policy["stance"] == "blocks_all_ai":
blocked.append({"url": url, "domain": domain, "stance": policy["stance"]})
else:
allowed.append({"url": url, "domain": domain, "stance": policy["stance"]})
except Exception as e:
unknown.append({"url": url, "domain": domain, "error": str(e)})
return {"allowed": allowed, "blocked": blocked, "unknown": unknown}
# Usage
urls = [
"https://nytimes.com/article/example",
"https://github.com/some/repo",
"https://wikipedia.org/wiki/AI",
"https://reddit.com/r/tech",
]
results = asyncio.run(batch_check(urls))
print(f"Allowed: {len(results['allowed'])}")
print(f"Blocked: {len(results['blocked'])}")
print(f"Unknown: {len(results['unknown'])}")curl: Quick domain lookup
For people who just want to check a domain from the terminal.
# Check a single domain
curl -s https://api.maango.io/v1/domain/nytimes.com \
-H "Authorization: Bearer maango_sk_xxxxx" | python3 -m json.tool
# Just get the stance
curl -s https://api.maango.io/v1/domain/nytimes.com \
-H "Authorization: Bearer maango_sk_xxxxx" | python3 -c "
import json, sys
d = json.load(sys.stdin)
print(f'{d["domain"]}: {d["stance"]}')
print(f' Training: {d["use_cases"]["training"]}')
print(f' Search: {d["use_cases"]["search"]}')
print(f' Inference:{d["use_cases"]["inference"]}')
"
# Search for news sites that block AI
curl -s "https://api.maango.io/v1/search?q=news&stance=blocks_all_ai&limit=10" \
-H "Authorization: Bearer maango_sk_xxxxx" | python3 -m json.toolBatch compare policies across competitors
Use the /batch endpoint to see how different sites in the same industry handle AI (up to 25 domains per request).
import httpx
MAANGO_KEY = "maango_sk_xxxxx"
def compare_industry(domains: list[str]):
"""Compare AI policies across a set of competing domains."""
r = httpx.post(
"https://api.maango.io/v1/batch",
headers={
"Authorization": f"Bearer {MAANGO_KEY}",
"Content-Type": "application/json"
},
json={"domains": domains}
)
data = r.json()
print(f"{'Domain':<25} {'Stance':<20} {'Training':<12} {'Search':<12} {'Inference'}")
print("-" * 80)
for d in data["domains"]:
uc = d.get("use_cases", {})
print(f"{d['domain']:<25} {d['stance']:<20} {uc.get('training', '?'):<12} {uc.get('search', '?'):<12} {uc.get('inference', '?')}")
if data.get("not_found"):
print(f"\nNot in registry: {', '.join(data['not_found'])}")
# Compare major news sites
compare_industry([
"nytimes.com",
"washingtonpost.com",
"theguardian.com",
"bbc.com",
"reuters.com"
])
# Compare social media platforms
compare_industry([
"twitter.com",
"facebook.com",
"reddit.com",
"linkedin.com",
"tiktok.com"
])