Skip to main content

Python client for the PrismaData location intelligence API

Project description

prismadata

Python client for the PrismaData location intelligence API.

Installation

pip install prismadata

With optional extras:

pip install prismadata[pandas]     # DataFrame enrichment
pip install prismadata[sklearn]    # scikit-learn transformer
pip install prismadata[all]        # everything (pandas, sklearn, cache, progress bars)

Quick Start

from prismadata import Client

client = Client(api_key="your-api-key")

# Geocode an address
result = client.geocode(full_address="Av Paulista 1000, Sao Paulo")
print(result["prismadata__geocoder__latitude"], result["prismadata__geocoder__longitude"])

# Query slum proximity
slum = client.slum(lat=-23.56, lng=-46.65)
print(slum["prismadata__favela__distancia_m"])

# Calculate a route
route = client.route([(-23.56, -46.65), (-23.57, -46.66)])
print(route["prismadata__routing_route__distancia_m"])

Authentication

The client supports two authentication methods:

# Using API key
client = Client(api_key="your-api-key")

# Using username and password
client = Client(username="your-user", password="your-pass")

Credentials can also be provided via environment variables:

export PRISMADATA_APIKEY="your-api-key"
# or
export PRISMADATA_USERNAME="your-user"
export PRISMADATA_PASSWORD="your-pass"
# Picks up credentials from environment automatically
client = Client()

Credential resolution order: explicit api_key > explicit username/password > PRISMADATA_APIKEY env var > PRISMADATA_USERNAME+PRISMADATA_PASSWORD env vars.

DataFrame Enrichment

import pandas as pd
from prismadata import Client

client = Client(api_key="your-api-key")

df = pd.DataFrame({
    "lat": [-23.56, -23.57, -23.58],
    "lng": [-46.65, -46.66, -46.67],
})

enriched = client.enrich(df, services=["slum", "income_static", "infosc"])
print(enriched.columns.tolist())
# ['lat', 'lng', 'prismadata__favela__distancia_m', ..., 'prismadata__personal_income_static__percentil_br', ...]

# Use clean_columns=True for shorter column names
client = Client(api_key="your-api-key", clean_columns=True)
enriched = client.enrich(df, services=["slum"])
# Column names: 'favela_distancia_m', 'favela_nome', ...

scikit-learn Pipeline

from sklearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestClassifier
from prismadata.sklearn import PrismaDataTransformer

pipe = Pipeline([
    ("enrich", PrismaDataTransformer(
        api_key="your-api-key",
        services=["slum", "income_static"],
    )),
    ("model", RandomForestClassifier()),
])

pipe.fit(X_train, y_train)

Async Client

All methods are available asynchronously via AsyncClient:

from prismadata import AsyncClient

async with await AsyncClient.create(api_key="your-api-key") as client:
    result = await client.slum(lat=-23.56, lng=-46.65)
    print(result)

    # Batch and enrichment work the same way
    enriched = await client.enrich(df, services=["slum", "income_static"])

Error Handling

from prismadata import Client
from prismadata.exceptions import (
    AuthenticationError,
    BatchError,
    RateLimitError,
    PrismaDataError,
)

try:
    result = client.slum_batch(large_point_dict)
except BatchError as e:
    # Some chunks succeeded, some failed
    print(f"Got {len(e.partial_results)} results, {len(e.failed_keys)} failed")
    for key, value in e.partial_results.items():
        process(key, value)  # use what succeeded
    retry(e.failed_keys)     # retry what failed
except RateLimitError:
    print("Rate limit exceeded, wait and retry")
except AuthenticationError:
    print("Invalid credentials")
except PrismaDataError as e:
    print(f"API error {e.status_code}: {e}")

Available Methods

Geocoding

  • client.geocode(full_address=..., zipcode=..., city=..., state=...) - Address to coordinates
  • client.reverse_geocode(lat, lng) - Coordinates to address

Location Services

  • client.slum(lat, lng) - Nearest slum/favela proximity
  • client.prison(lat, lng) - Nearest prison proximity
  • client.border(lat, lng) - Border proximity
  • client.infosc(lat, lng) - Census sector info
  • client.income_static(lat, lng) - Income percentiles
  • client.income_pdf(lat, lng, gender=..., age=...) - Detailed income statistics

Routing

  • client.route(points, profile="car") - Route between points
  • client.isochrone(lat, lng, time_limit=600, profile="car") - Reachable area

Address Validation

  • client.compare_address(lat, lng, full_address=...) - Compare address with coordinates
  • client.validate_address(locations, addresses) - Validate against location history
  • client.cluster_locations(locations) - Cluster location history

Credit

  • client.precatory(cpf_cnpj=...) - Credit summary (precatorios/RPVs)
  • client.precatory_detail(cpf_cnpj=...) - Detailed credit list

Batch Operations

  • client.slum_batch(points) - Batch slum queries
  • client.prison_batch(points) - Batch prison queries
  • client.border_batch(points) - Batch border queries
  • client.infosc_batch(points) - Batch census sector queries
  • client.route_batch(items, profile="car") - Batch routing
  • client.isochrone_batch(items, profile="car") - Batch isochrones

Aggregator

  • client.aggregate(lat, lng, services=[...]) - Multiple services in one call
  • client.aggregate_batch(points, services=[...]) - Batch aggregation
  • client.geocode_aggregate(full_address=..., services=[...]) - Geocode + aggregate

Configuration

client = Client(
    api_key="your-key",
    timeout=30,            # Request timeout (seconds)
    cache=True,            # Enable disk cache (requires diskcache)
    cache_ttl=86400,       # Cache TTL (seconds)
    clean_columns=False,   # Keep 'prismadata__' prefix (default)
    show_progress=True,    # Show tqdm progress bars
    app_name="my-app",     # Sent as X-App header on every request
)

License

MIT

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

prismadata-0.4.4.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

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

prismadata-0.4.4-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

Details for the file prismadata-0.4.4.tar.gz.

File metadata

  • Download URL: prismadata-0.4.4.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.0 Linux/6.19.8-arch1-1

File hashes

Hashes for prismadata-0.4.4.tar.gz
Algorithm Hash digest
SHA256 5f1fab6ace6c12d29a93a78641e63b4584513aac964ca498bc9bfef51d677aea
MD5 757050a206effb286dcb09293f12dac3
BLAKE2b-256 9e6790d79b3eb24c3d9a4c37252d1304f941f8a139890c6991ca899a2a817088

See more details on using hashes here.

File details

Details for the file prismadata-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: prismadata-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 36.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.0 Linux/6.19.8-arch1-1

File hashes

Hashes for prismadata-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1507e11f0f3ca94a5075c986631bd06bb7b77a29912336b07bc75be1781d41ae
MD5 155d69a744e6801ec865376b55a377b8
BLAKE2b-256 16b1707a4781caac1f430dffec1ed71e5cfb30e6f70564e6a8462afb839b1dbd

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