amap-python-sdk
English | 简体中文
Overview
amap is a Python client for the Amap (Gaode) Web Service APIs. It provides a synchronous client for everyday use and a matching asynchronous client for applications built around asyncio.
The SDK currently wraps Place Search, Weather, District, Geocoding, Directions, Distance, Coordinate Conversion, Input Tips, IP Location, and Traffic Status APIs. Check the linked Amap documentation for service availability, required permissions, and current API limits.
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. Keep it out of source control. For example, set an environment variable before running your application:
export AMAP_API_KEY="your-api-key"
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())
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.
Logging
amap uses Python's standard logging module and does not configure handlers or log levels for your application. Successful requests are logged at DEBUG; API, HTTP, and timeout failures are logged at WARNING. Log messages include the endpoint and diagnostic status, but omit API keys, request parameters, and response bodies.
Configure logging in your application when needed:
import logging
logging.basicConfig(level=logging.DEBUG)
Requirements
- Python
>=3.10,<4.0 requestsfor the synchronous clientaiohttpfor the asynchronous client
Exact dependency constraints are maintained in pyproject.toml.
Contributing
Contributions are welcome:
- Fork the repository and create a branch for your change.
- Install the project and development groups with
uv sync --all-groups. - Run the relevant tests with
uv run pytest. - Open a pull request with a concise description of the change.
Please add or update tests for behavior changes and follow the existing formatting and typing conventions.
Releases
Publishing a GitHub Release builds and tests the package, then publishes it to PyPI using Trusted Publishing. Configure a PyPI Trusted Publisher for project amap-python-sdk, repository owner sunkunxi, repository amap-python-sdk, workflow filename publish.yml, and GitHub environment pypi.
License
MIT
Metadata
Release files for amap-python-sdk 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| amap_python_sdk-0.1.4.tar.gz | 183.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| amap_python_sdk-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 206.1 kB
Release files / amap_python_sdk-0.1.4.tar.gz
| Download URL | amap_python_sdk-0.1.4.tar.gz |
|---|---|
| Size | 183.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e64f3f696d4fc1834d233caacab4ce7a766613f177a633b2a97dc88712feea2
|
|
BLAKE2b-256 checksum How to use checksums |
daaed5c234f836446298d06907bf8f3021b16823cdea429de677edaa28371b15
|
| 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.4-py3-none-any.whl
| Download URL | amap_python_sdk-0.1.4-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
252bb063601365a36d4ce6ebba444e9b5802cdb2435e7edfe2d0df69b3b9e0b6
|
|
BLAKE2b-256 checksum How to use checksums |
78d61cda18c9872580d2c1b7f89b3be2ac4ad47334fa9af5c1ed8c918315a29f
|
| 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.4
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.