Python SDK
A fully-typed Python SDK for the Layers API built on httpx and Pydantic v2.
Download
Download layers-sdk-python.zipInstallation
# Unzip the archive, then install
unzip layers-sdk-python.zip
pip install .
Or install the dependencies directly:
pip install httpx pydantic
Then place the layers_sdk/ directory in your project.
Requirements
- Python >= 3.10
httpx >= 0.27pydantic >= 2.0
Quick Start
from layers_sdk import LayersClient, PortfolioFilter, Feature, Geometry, GeometryType
client = LayersClient(base_url="https://your-api-host.com", api_key="your-api-key")
# Geocode an address
result = client.location.geocode(q="10 Downing Street, London")
print(result.lat, result.lon)
# Query points inside a polygon
shape = Feature(
type="Feature",
geometry=Geometry(
type=GeometryType.POLYGON,
polygon=[[[13.0, 52.0], [14.0, 52.0], [14.0, 53.0], [13.0, 53.0], [13.0, 52.0]]],
),
)
points = client.reports_v1.points_selection(source="my_source", shape=shape)
# Enrich a single point
enriched = client.enrichment.enrich_single(
lat=48.8, lng=2.3, layers=["flood"], operation="enhance"
)
# Generate a risk report as PDF
from layers_sdk import PointRiskRequestPayload, PointRiskLayers
pdf = client.risk.point_risk(PointRiskRequestPayload(
point=Geometry(type=GeometryType.POINT, point=[13.4, 52.5]),
layers=PointRiskLayers(source="flood", names=["flood_zone"]),
))
with open("report.pdf", "wb") as f:
f.write(pdf)
API Reference
The SDK exposes all services through the LayersClient object:
| Property | Description |
|---|---|
client.location | Autocomplete, geocode, reverse geocode |
client.reports_v1 | Portfolio reports with V1 filters (PortfolioFilter) |
client.reports_v2 | Portfolio reports with V2 filters (RequestFilter) |
client.risk | Risk report generation (PDF/HTML) |
client.enrichment | Single-point and batch enrichment |
client.wfs | OGC WFS GetFeature |
client.wms | OGC WMS GetCapabilities, GetMap, GetFeatureInfo, GetLegendGraphic, DescribeLayer |
Location
# Autocomplete
results = client.location.autocomplete(q="Berlin")
# Geocode
result = client.location.geocode(q="10 Downing Street, London")
# Reverse geocode
result = client.location.reverse_geocode(lat="51.5034", lon="-0.1276")
Reports V1
from layers_sdk import PortfolioFilter, Feature, Buffer, Coordinates
filters = [PortfolioFilter(field="oe_id", value="my-oe")]
# Accumulation inside a shape
results = client.reports_v1.accumulation_selection(
source="my_source", shape=my_feature, filters=filters,
aggregation_columns=["insured_value"],
)
# Accumulation inside a buffer
buffer = Buffer(type="circle", coordinates=[Coordinates(lat=52.52, long=13.405)])
results = client.reports_v1.accumulation_buffer(
source="my_source", shape=buffer, radiuses=[1000, 5000], filters=filters,
)
# Entries (JSON or CSV)
entries = client.reports_v1.entries_selection(source="src", shape=my_feature)
csv_bytes = client.reports_v1.entries_selection(
source="src", shape=my_feature, accept="text/csv"
)
# Points
points = client.reports_v1.points_selection(source="src", shape=my_feature)
# Point attributes
attrs = client.reports_v1.points_attributes(source="src", value=123)
# Provision
provision = client.reports_v1.get_provision()
Reports V2
Same methods as V1, but uses RequestFilter instead of PortfolioFilter:
from layers_sdk import RequestFilter
filters_v2 = [RequestFilter(field="oe_id", value="my-oe")]
results = client.reports_v2.accumulation_selection(
source="my_source", shape=my_feature, filters_v2=filters_v2,
)
entries = client.reports_v2.entries_selection(
source="src", shape=my_feature, filters_v2=filters_v2,
)
Risk Reports
from layers_sdk import (
PointRiskRequestPayload, PointRiskLayers,
PointBufferRiskRequestPayload, PointBufferRiskLayers, ReportBuffer,
Geometry, GeometryType,
)
# Point risk report (PDF)
pdf = client.risk.point_risk(PointRiskRequestPayload(
point=Geometry(type=GeometryType.POINT, point=[13.4, 52.5]),
layers=PointRiskLayers(source="flood", names=["flood_zone"]),
))
# Point risk report (HTML preview)
html = client.risk.point_risk(payload, accept="text/html")
# Point-buffer risk report
pdf = client.risk.point_buffer_risk(PointBufferRiskRequestPayload(
point=Geometry(type=GeometryType.POINT, point=[13.4, 52.5]),
source="my_source",
buffer=ReportBuffer(radiuses=[1000, 5000], style="solid"),
))
# V2 variants
pdf = client.risk.point_risk_v2(payload)
pdf = client.risk.point_buffer_risk_v2(payload)
Enrichment
from layers_sdk import PointRequest
# Single point
result = client.enrichment.enrich_single(
lat=48.8, lng=2.3, layers=["flood", "earthquake"], operation="enhance"
)
# Batch
results = client.enrichment.enrich_batch(
points=[PointRequest(id="p1", lat=48.8, lng=2.3)],
layers=["flood"],
operation="count",
)
WFS
features = client.wfs.get_feature(
type_names="namespace:featuretype",
count=100,
bbox="0,0,10,10,EPSG:4326",
cql_filter="population > 1000",
)
WMS
# Capabilities XML
xml = client.wms.get_capabilities()
# Map image
png_bytes = client.wms.get_map(
layers="GRAPHRASTER:light_pollution",
srs="EPSG:3857",
bbox="975947,6657970,1533632,7037098",
width=256, height=256,
)
# Feature info
info = client.wms.get_feature_info(
layers="GRAPHRASTER:light_pollution", styles="", srs="EPSG:3857",
bbox="2554219,5763351,2554220,5763352", width=10, height=10,
query_layers="GRAPHRASTER:light_pollution", x=5, y=5,
)
# Legend graphic
legend = client.wms.get_legend_graphic(
layer="GRAPHRASTER:light_pollution", styles="default",
)
# Describe layer
desc = client.wms.describe_layer(layers="GRAPHRASTER:light_pollution")
Error Handling
from layers_sdk.exceptions import BadRequestError, ForbiddenError, ServerError
try:
client.reports_v1.entries_selection(source="src", shape=my_feature)
except BadRequestError as e:
print(f"Bad request: {e.message}")
except ForbiddenError:
print("Access denied")
except ServerError as e:
print(f"Server error ({e.status_code}): {e.message}")
Package Structure
layers_sdk/
├── __init__.py # Package exports
├── client.py # LayersClient + _BaseAPI
├── exceptions.py # Exception hierarchy
├── py.typed # PEP 561 marker
├── models/
│ ├── __init__.py
│ ├── geojson.py # Feature, Geometry, GeometryType, Buffer, Coordinates
│ ├── filters.py # PortfolioFilter, RequestFilter, FiltersPayload
│ ├── errors.py # ErrorMessage, ErrorMessageResponse, ErrorResponse
│ ├── location.py # AutocompleteResult, GeocodeResult, ReverseGeocodeResult
│ ├── enrichment.py # PointRequest, BatchRequestOptions
│ ├── provisioning.py # PortfolioProvisionResponse + config sub-models
│ ├── reports.py # All V1/V2 request/response models
│ └── risk.py # Risk report payloads
├── api/
│ ├── __init__.py
│ ├── location.py # LocationAPI
│ ├── reports_v1.py # ReportsV1API
│ ├── reports_v2.py # ReportsV2API
│ ├── risk.py # RiskAPI
│ ├── enrichment.py # EnrichmentAPI
│ ├── wfs.py # WFSAPI
│ └── wms.py # WMSAPI
pyproject.toml # pip-installable package config