Skip to main content

pyamap

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 pyamap

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 pyamap 2.0.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 pyamap 2.0.0
File Size Uploaded Provenance Actions
pyamap-2.0.0.tar.gz 182.8 kB Without provenance Details for pyamap-2.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 205.4 kB

Release files / pyamap-2.0.0.tar.gz

Download URL pyamap-2.0.0.tar.gz
Size 182.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4417b678882d4992575e49e78a1295f024720e19855da218c79c9ae6cac3ad25
BLAKE2b-256 checksum
How to use checksums
a518a7945364f7fa1fc8ed5896feaf9253b7de17d179923ea12507d70bf36231
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 / pyamap-2.0.0-py3-none-any.whl

Download URL pyamap-2.0.0-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
226e8cb2c862600c7fada1c706ebfa7fad703232b5bae7844a57e0a85b9e34f0
BLAKE2b-256 checksum
How to use checksums
c1b9195d0750a88837589e3f0541d90d6786eb880bc5db2e21e0009540770edb
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 pyamap 2.0.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.

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.

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