Official Python library for integrating with Perimi's video intelligence platform
Install via pip with all dependencies included
Full type annotation support for better IDE experience
Built-in async/await support for high-performance applications
Automatic API key management and token refresh
pip install perimi-pythonInstall the Perimi Python SDK via pip
# Install from PyPI
pip install perimi-python
# Or install with async support
pip install perimi-python[async]Initialize the client and start making API calls
from perimi import Perimi
# Initialize with API key
client = Perimi(api_key="your-api-key")
# List all streams
streams = client.streams.list()
print(f"Found {len(streams)} streams")
# Get stream details
stream = client.streams.get("stream-id")
print(f"Stream: {stream.name} - Status: {stream.status}")Create and manage video streams
# Create a new stream
stream = client.streams.create(
name="Warehouse Camera 1",
location="Building A - Entrance",
connection_url="rtsp://192.168.1.100:554/stream",
credentials={
"username": "admin",
"password": "password123"
},
tags=["entrance", "high-priority"]
)
# Update stream configuration
stream.update(
detection_zones=[
{
"name": "Entry Zone",
"coordinates": [[100, 100], [400, 100], [400, 300], [100, 300]]
}
]
)
# Delete a stream
stream.delete()Retrieve and process anomaly detections
# Get recent anomalies
anomalies = client.anomalies.list(
stream_id="stream-id",
since="2024-01-14T00:00:00Z",
limit=100
)
# Process each anomaly
for anomaly in anomalies:
print(f"Anomaly detected: {anomaly.type}")
print(f"Confidence: {anomaly.confidence:.2f}")
print(f"Timestamp: {anomaly.timestamp}")
if anomaly.confidence > 0.8:
# High confidence - send alert
client.alerts.send(
stream_id=anomaly.stream_id,
message=f"High confidence {anomaly.type} detected"
)Use async client for better performance
import asyncio
from perimi import AsyncPerimi
async def main():
# Initialize async client
client = AsyncPerimi(api_key="your-api-key")
# Concurrent API calls
streams, anomalies = await asyncio.gather(
client.streams.list(),
client.anomalies.list(limit=50)
)
print(f"Streams: {len(streams)}, Anomalies: {len(anomalies)}")
# Clean up
await client.close()
# Run async function
asyncio.run(main())Robust error handling and retry logic
from perimi import Perimi, PerimiError, RateLimitError
client = Perimi(api_key="your-api-key")
try:
stream = client.streams.get("invalid-id")
except PerimiError as e:
if e.status_code == 404:
print("Stream not found")
elif isinstance(e, RateLimitError):
print(f"Rate limited. Retry after: {e.retry_after} seconds")
else:
print(f"API error: {e.message}")
# Built-in retry with exponential backoff
from perimi.retry import with_retry
@with_retry(max_attempts=3, backoff=2.0)
def create_stream_with_retry():
return client.streams.create(
name="Retry Test Stream",
connection_url="rtsp://example.com/stream"
)client.streams.list()List all streams
client.streams.get(id)Get stream by ID
client.streams.create(**kwargs)Create new stream
client.anomalies.list(**filters)List anomalies with filters
PERIMI_API_KEYEnvironment variable for API key
PERIMI_BASE_URLCustom API endpoint (optional)
PERIMI_TIMEOUTRequest timeout in seconds
PERIMI_DEBUGEnable debug logging
Start integrating Perimi into your Python applications today