Skip to main content

Python SDK for SpatialFlow - Real-time geospatial automation platform

Project description

SpatialFlow Python SDK

The official Python SDK for SpatialFlow - a real-time geospatial automation platform.

Installation

pip install spatialflow

Quick Start

import asyncio
from spatialflow import SpatialFlow, models

async def main():
    # Initialize with API key
    async with SpatialFlow(api_key="sf_xxx") as client:
        # List geofences
        response = await client.geofences.apps_geofences_api_list_geofences()
        for geofence in response.results:
            print(f"{geofence.name}: {geofence.id}")

        # Create a geofence
        geofence = await client.geofences.apps_geofences_api_create_geofence(
            models.CreateGeofenceRequest(
                name="My Region",
                geometry={
                    "type": "Polygon",
                    "coordinates": [[[-122.4, 37.8], [-122.4, 37.7], [-122.3, 37.7], [-122.3, 37.8], [-122.4, 37.8]]]
                }
            )
        )

asyncio.run(main())

Authentication

API Key (Recommended for server-side)

client = SpatialFlow(api_key="sf_xxx")

JWT Token (For client-side apps)

client = SpatialFlow(access_token="eyJ...")

Resources

  • Geofences - Create and manage geofences
  • Workflows - Automate location-based actions
  • Webhooks - Receive real-time event notifications
  • Devices - Track device locations

Method Naming

API methods are auto-generated from the OpenAPI spec and follow the pattern: apps_{resource}_api_{operation}. For example:

# Geofences
client.geofences.apps_geofences_api_list_geofences()
client.geofences.apps_geofences_api_create_geofence(...)
client.geofences.apps_geofences_api_get_geofence(id=...)
client.geofences.apps_geofences_api_update_geofence(id=..., ...)
client.geofences.apps_geofences_api_delete_geofence(id=...)

# Workflows
client.workflows.apps_workflows_api_list_workflows()
client.workflows.apps_workflows_api_create_workflow(...)

# Webhooks
client.webhooks.apps_webhooks_api_list_webhooks()
client.webhooks.apps_webhooks_api_create_webhook(...)

Use your IDE's autocomplete to discover available methods, or see the API Reference for the full list.

Webhook Verification

Verify incoming webhook signatures to ensure they're from SpatialFlow:

from spatialflow import verify_webhook_signature, WebhookSignatureError

# In your webhook handler (e.g., FastAPI/Flask)
@app.post("/webhook")
async def handle_webhook(request):
    payload = await request.body()
    signature = request.headers.get("X-SF-Signature")

    try:
        event = verify_webhook_signature(
            payload=payload,
            signature=signature,
            secret=WEBHOOK_SECRET,
        )
        print(f"Event type: {event['type']}")
        return {"status": "ok"}
    except WebhookSignatureError as e:
        return {"error": str(e)}, 400

Pagination

Use the async paginator to iterate through all results:

from spatialflow import paginate

async def fetch_page(offset, limit):
    return await client.geofences.apps_geofences_api_list_geofences(
        offset=offset, limit=limit
    )

async for geofence in paginate(fetch_page):
    print(geofence.name)

File Uploads

Upload geofence files (GeoJSON, KML, GPX) with automatic job polling:

from spatialflow import upload_geofences

result = await upload_geofences(
    client,
    "boundaries.geojson",
    group_name="my-region",
    timeout=120,
    on_status=lambda status, _: print(f"Status: {status}"),
)

print(f"Created {result.created_count} geofences")
for geofence in result.created_geofences:
    print(f"  - {geofence['name']} ({geofence['id']})")

Async Job Polling

For lower-level control over job polling:

from spatialflow import poll_job, JobTimeoutError, JobFailedError

async def get_status():
    return await client.geofences.apps_geofences_api_get_upload_job_status(
        job_id=job_id
    )

try:
    result = await poll_job(
        get_status,
        timeout=120,
        poll_interval=2.0,
        on_status=lambda status, _: print(f"Status: {status}"),
    )
    print(f"Job completed: {result.created_count} created")
except JobTimeoutError as e:
    print(f"Job timed out after {e.timeout}s (last status: {e.last_status})")
except JobFailedError as e:
    print(f"Job failed: {e.error_message}")

Models

Request/response models are available via the models namespace:

from spatialflow import models

# Common models
models.CreateGeofenceRequest
models.GeofenceResponse
models.CreateWebhookRequest
models.WebhookResponse
models.WorkflowIn
models.WorkflowOut

# Explore all available models
print([m for m in dir(models) if not m.startswith('_')])

Documentation

Support

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spatialflow-0.1.0.tar.gz (242.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spatialflow-0.1.0-py3-none-any.whl (621.9 kB view details)

Uploaded Python 3

File details

Details for the file spatialflow-0.1.0.tar.gz.

File metadata

  • Download URL: spatialflow-0.1.0.tar.gz
  • Upload date:
  • Size: 242.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for spatialflow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f9445af4cc415ee04d1f2af79207bce4959b68f5e1961bc864dabf93d7101116
MD5 dd23297c43e2b30a90c15d23389d6f25
BLAKE2b-256 9b950508cf5b54a31a2153acde8ee8b23e977f71b3a3d23f958e4631740170e1

See more details on using hashes here.

File details

Details for the file spatialflow-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spatialflow-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 621.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for spatialflow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 008e995eac2b868a697ae63bddb9037611dba8c9a86f76a10f0f66e1cb41d30c
MD5 da86bfd43a53f450c7ed6a5d4c9200b7
BLAKE2b-256 49d35d73f9b33174ffdaf4de92ad0ea5218b4d01f51de6aeda6613c890edcde7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page