Skip to main content

Mapricot for Python

The official Python client for the Mapricot API: address and place search, reverse geocoding, nearby places, routing, and IP geolocation, with 250,000 free requests every month.

pip install mapricot

It needs Python 3.11 or later and has no dependencies.

Quick start

Create a server key in the dashboard and pass it to the client. Keep it out of your source code, for example by reading it from an environment variable as here.

import os

from mapricot import Mapricot

client = Mapricot(os.environ["MAPRICOT_KEY"])

data = client.geocoding.search("128 SW 3rd Ave, Portland", limit=1)
place = data["results"][0]
print(place["label"], place["lat"], place["lon"])

Methods

Methods are grouped by product, the same way as the API's paths. Each returns the API's JSON as a typed dict, with the same field names as the API reference.

Method Endpoint
client.geocoding.search(q, focus=, country=, limit=, lang=) GET /geocoding/v1/search
client.geocoding.search_batch(queries) POST /geocoding/v1/search/batch
client.geocoding.autocomplete(q, focus=, country=, limit=, lang=) GET /geocoding/v1/autocomplete
client.geocoding.reverse(lat, lon, limit=, lang=) GET /geocoding/v1/reverse
client.places.nearby(lat, lon, category=, radius=, limit=, lang=) GET /places/v1/nearby
client.places.get(id, lang=) GET /places/v1/{id}
client.routing.route(waypoints, mode=, geometries=, steps=, lang=) POST /routing/v1/route
client.routing.optimize(waypoints, mode=, geometries=, steps=, lang=) POST /routing/v1/optimize
client.routing.isochrone(location, minutes, mode=) POST /routing/v1/isochrone
client.ip_geolocation.lookup(ip) GET /ip-geolocation/v1/{ip}
client.account() GET /account, which checks a key and is never billed

focus and each waypoint are {"lat": …, "lon": …}. country and category take a list or a comma-separated string.

nearby = client.places.nearby(45.52, -122.68, category=["food:coffee_shop"], radius=1000)
route = client.routing.route([{"lat": 45.5189, "lon": -122.6793}, {"lat": 45.5214, "lon": -122.6828}], mode="walk")
print(route["routes"][0]["durationSeconds"])

search_batch runs up to 100 searches in one request. Each query is a dict of search's parameters, and responses answers them in the same order, each with results and attribution, or an error with the code and message that search would get, without raising. Each completed search is billed as one request; errors aren't.

batch = client.geocoding.search_batch([{"q": "128 SW 3rd Ave, Portland", "limit": 1}, {"q": "10 Downing Street, London", "limit": 1}])
for response in batch["responses"]:
    print(response["error"]["message"] if "error" in response else response["results"][0]["label"])

A route's path comes as an encoded polyline with five decimal places, which polyline decoders assume. Pass geometries="geojson" to get it as a GeoJSON LineString in geometry instead, which maps draw without decoding, or geometries="polyline6" for six decimal places.

Pass steps=True and each leg's steps has its turn-by-turn directions: an instruction, its distance and time, and its lat and lon. They're in English unless you pass lang, such as lang="fr".

routing.optimize takes the same arguments as routing.route and returns the route that visits the waypoints in a fast order, keeping the first and last in place. It adds waypointOrder: the indexes of your waypoints in visiting order, which legs follow. Every pair of waypoints must be within 400 km of each other for drive, or 200 km for walk and bicycle.

An isochrone is a GeoJSON FeatureCollection with one polygon per time, largest first, so a map that draws them in order shows the smaller ones on top:

area = client.routing.isochrone({"lat": 45.5189, "lon": -122.6793}, [5, 10], mode="walk")
print([feature["properties"]["minutes"] for feature in area["features"]])

If your app shows results, show the credits in each response's attribution.

Errors and retries

An error response raises MapricotError, with the HTTP status, the API's error code, a message, and the request_id:

from mapricot import MapricotError

try:
    client.geocoding.search("")
except MapricotError as error:
    print(error.status, error.code, error.message)  # 400 invalid_request The service rejected the request.

The client retries 503 responses and 429 concurrency_exceeded, up to twice, waiting longer each time. Errors aren't billed. Set max_retries= and timeout= (seconds) on Mapricot(...) to change this. The API reference lists every status.

Metadata

Release files for mapricot 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mapricot 0.11.0
File Size Uploaded Provenance Actions
mapricot-0.11.0.tar.gz 10.2 kB With provenance Details for mapricot-0.11.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mapricot 0.11.0
File Interpreter ABI Platform Actions
mapricot-0.11.0-py3-none-any.whl Python 3 none any Details for mapricot-0.11.0-py3-none-any.whl

Total release size: 18.1 kB

Release files / mapricot-0.11.0.tar.gz

Download URL mapricot-0.11.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
39c016962bacb01dae2d5df74dcbb833ceaf9ae6f6b83256193c1158dd6ce64f
BLAKE2b-256 checksum
How to use checksums
41c8b1538d091869bea4ca03c578262c143abb20b38146b45f8a7cc2d2ace4da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / mapricot-0.11.0-py3-none-any.whl

Download URL mapricot-0.11.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52558bbbd4afba760554c5dfdd5d03b0c32348bc49b45b69e1f10360cc233240
BLAKE2b-256 checksum
How to use checksums
905e29f3e233591eb5e83d6a32333172f1633cf0fedac8793f499bb19271f7c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Security for mapricot 0.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mapricot-0.11.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page