Skip to main content

amap-python-sdk

Test Coverage PyPI version Python versions

English | 简体中文

Overview

This repository is a Python client for the Amap (Gaode) Web Service APIs. It provides a synchronous client and a matching asynchronous client for applications built around asyncio.

See the "Available APIs" section below for a table of the Web APIs wrapped by this SDK.

Installation

pip install amap-python-sdk

The PyPI distribution is named amap-python-sdk; the Python import package remains amap. The package supports Python 3.10 and later, and installs its HTTP dependencies (requests and aiohttp) automatically.

API key

Create a Web Service API key in the Amap developer console.

Synchronous usage

The synchronous client is the recommended starting point. Methods return the parsed Amap JSON response as a dictionary.

import os

from amap import Amap

amap = Amap(os.environ["AMAP_API_KEY"])
try:
    # POI keyword search
    pois = amap.place.text(
        "coffee",
        region="上海",
        city_limit=True,
        page_size=10,
        page_num=1,
    )

    # Nearby search; coordinates are (longitude, latitude)
    nearby = amap.place.around(
        "coffee",
        location=("121.4737", "31.2304"),
        radius=1500,
    )

    # Search within a closed polygon (first and last points match)
    in_area = amap.place.polygon(
        ("116.4074", "39.9042"),
        ("116.4200", "39.9042"),
        ("116.4200", "39.9150"),
        ("116.4074", "39.9042"),
        keywords="museum",
    )

    # Retrieve a POI by its Amap ID
    poi = amap.place.detail("YOUR_POI_ID")

    # Other services
    weather = amap.weather.info("110000")
    districts = amap.district.list("北京市")
    geocode = amap.georegeo.geo("北京市朝阳区阜通东大街6号")
    reverse_geocode = amap.georegeo.regeo(("116.481488", "39.990464"))
    route = amap.direction.driving(
        ("116.481028", "39.989643"),
        ("116.434446", "39.90816"),
    )
finally:
    amap.close()

Coordinates are provided as (longitude, latitude). The methods accept endpoint-specific keyword arguments; refer to their docstrings and the corresponding Amap API documentation for the full parameter list.

Asynchronous usage

amap.aio.Amap provides the corresponding asyncio client, implemented with aiohttp. Its service methods mirror the synchronous client.

import asyncio
import os

from amap.aio import Amap


async def main():
    async with Amap(os.environ["AMAP_API_KEY"]) as amap:
        result = await amap.place.text("coffee", region="上海")
        print(result)


asyncio.run(main())

Available APIs

The SDK wraps the following Amap Web APIs:

API Description Client module
Place Search (POI) Keyword, nearby, polygon, and detail searches for points of interest amap.place
Weather Current weather and forecasts amap.weather
District Administrative district lookup and listing amap.district
Geocoding Forward and reverse geocoding amap.georegeo
Directions Route planning (driving, walking, etc.) amap.direction
Distance Distance measurement and matrix queries amap.distance
Coordinate Conversion Convert between coordinate systems amap.coordinate
Input Tips Autocomplete / input suggestion service amap.inputtips
IP Location IP-based location lookup amap.ip
Traffic Status Traffic condition and incident queries amap.traffic

Service availability, required permissions, and API limits should be checked in the official Amap documentation.

Errors

If Amap returns a JSON response with "status": "0", the client raises amap.exceptions.AmapAPIError. The exception exposes the original response, info, and infocode:

from amap.exceptions import AmapAPIError

try:
    result = amap.place.text("coffee")
except AmapAPIError as exc:
    print(exc.infocode, exc.info)
    print(exc.response)

The SDK preserves Amap's infocode instead of guessing its meaning from a numeric prefix. Check the official Amap error-code reference and the documentation for the specific API. When the underlying HTTP library reports a request timeout, the client raises amap.exceptions.AmpTimeoutError; other network and HTTP transport errors are raised by requests or aiohttp.

Requirements

  • Python >=3.10,<4.0
  • requests for the synchronous client
  • aiohttp for the asynchronous client

Exact dependency constraints are maintained in pyproject.toml.

Contributing

Contributions are welcome. If submitting changes, please include unit tests for any behavior changes or new features.

Run the test suite with:

uv run pytest

License

MIT

Metadata

Release files for amap-python-sdk 0.1.5

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

Source distribution (sdist)

Source distribution for amap-python-sdk 0.1.5
File Size Uploaded Provenance
amap_python_sdk-0.1.5.tar.gz 182.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for amap-python-sdk 0.1.5
File Interpreter ABI Platform
amap_python_sdk-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 205.7 kB

Release files / amap_python_sdk-0.1.5.tar.gz

Download URL amap_python_sdk-0.1.5.tar.gz
Size 182.9 kB
Tags Source
SHA-256 checksum
How to use checksums
70a2eecb53e426f9aef3f77b79e6135be3d635819b0e77bba2d2832690dcba43
BLAKE2b-256 checksum
How to use checksums
b1a90cf0dc65cb1f13f42eda7b9e35cd8619d93c3b80fe1600ca575e347778ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / amap_python_sdk-0.1.5-py3-none-any.whl

Download URL amap_python_sdk-0.1.5-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc8486713e362e797030041a1980fce12dc8596d4acc024bdaef16c1df416742
BLAKE2b-256 checksum
How to use checksums
0ece74ad75ce47e7f8d1eca3fb812f95d2b4f546cb2e49287ad66e5a27ca5f97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for amap-python-sdk 0.1.5

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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