Official clients
Official clients are maintained by the PASTOR team and track the latest API version.
Python
pip install pastor-sdkimport os
from pastor import PastorClient
client = PastorClient(api_key=os.environ["PASTOR_API_KEY"])
risk = client.m1.daily(municipio_id="05001", date_from="2025-07-01", date_to="2025-07-28")
print(risk.risk_label) # "MEDIUM"Repository: github.com/pastormap/pastor-sdk-python
JavaScript / TypeScript
npm install @pastormap/sdkimport { PastorClient } from "@pastormap/sdk";
const client = new PastorClient({ apiKey: process.env.PASTOR_API_KEY });
const risk = await client.m1.daily({ municipio_id: "05001", date_from: "2025-07-01", date_to: "2025-07-28" });
console.log(risk.risk_label); // "MEDIUM"Repository: github.com/pastormap/pastor-sdk-js
Code examples
Fetch daily risk and send an email alert
A Python script that checks the current risk level for a list of municipalities and sends an email summary:
import os, requests
headers = {"Authorization": f"Bearer {os.environ['PASTOR_API_KEY']}"}
base = "https://api.pastormap.com"
today = "2025-07-28"
municipalities = ["05001", "06001", "10001"]
alerts = []
for municipio_id in municipalities:
resp = requests.get(
f"{base}/api/v3/m1",
headers=headers,
params={"municipio_id": municipio_id, "date_from": today, "date_to": today},
)
data = resp.json()
if data.get("risk_label") == "HIGH":
alerts.append(
f"{municipio_id}: risk_score={data['risk_score']:.2f} ({data['risk_label']})"
)
if alerts:
# send_email is a placeholder for your email delivery library
send_email(
to="emergencies@example.com",
subject="PASTOR risk alert",
body="\n".join(alerts),
)Query ecosystem data for a municipality
Retrieve ecosystem and biomass data using the M10 module:
import os, requests
headers = {"Authorization": f"Bearer {os.environ['PASTOR_API_KEY']}"}
response = requests.get(
"https://api.pastormap.com/api/v3/m10",
headers=headers,
params={"municipio_id": "05001"},
)
response.raise_for_status()
data = response.json()
print(data)Generate and download a PDF report
import os, requests
headers = {"Authorization": f"Bearer {os.environ['PASTOR_API_KEY']}"}
response = requests.post(
"https://api.pastormap.com/api/v1/report",
headers=headers,
json={"municipio_id": "05001", "periodo": "2025-07"},
)
response.raise_for_status()
with open("risk_report.pdf", "wb") as f:
f.write(response.content)
print("Downloaded risk_report.pdf")Webhook verification example
If webhook integration is available for your account, verify incoming webhook payloads in Python using hmac from the standard library:
import hmac, hashlib, os
def verify_pastor_webhook(payload: bytes, signature: str, secret: str) -> bool:
expected = hmac.new(
secret.encode(),
payload,
hashlib.sha256,
).hexdigest()
return hmac.compare_digest(f"sha256={expected}", signature)
# In your Flask/FastAPI handler:
# signature = request.headers.get("X-Pastor-Signature", "")
# if not verify_pastor_webhook(request.body, signature, os.environ["PASTOR_WEBHOOK_SECRET"]):
# return 401