China Division 中国行政区划查询工具
一个高效查询中国行政区划的Python库,支持:
- 按代码或名称查询行政区划
- 智能分级匹配算法
- 上下级关系查询
安装方式
pip install china-division
快速开始
from china_division import search_division, get_division_info
# 通过名称查询
print(search_division("阿鲁科尔沁旗")) # 输出: "150421"
print(search_division("铁东")) # 输出: "210302:辽宁省鞍山市铁东区|220303:吉林省四平市铁东区"
# 通过代码查询
print(get_division_info("150421")) # 输出: "内蒙古自治区赤峰市阿鲁科尔沁旗"
主要功能
1. 行政区划查询
# 搜索行政区划(支持模糊匹配)
result = search_division("北京朝阳")
# 获取完整信息
info = get_division_info("110105") # 北京市朝阳区
2. 层级关系查询
from china_division import get_parent_division, get_child_divisions
# 获取上级行政区划
parent = get_parent_division("150421") # ("150400", "赤峰市")
# 获取下级行政区划
children = get_child_divisions("110000") # [("110101", "东城区"), ...]
3. 智能搜索特性
- 分级匹配:
search_division("内蒙阿鲁")→ 自动匹配"阿鲁科尔沁旗" - 多结果合并:多个结果用
|分隔显示 - 容错处理:无结果返回提示信息
数据来源
内置最新行政区划数据,包含:
- 省级行政区(23省、5自治区、4直辖市、2特别行政区)
- 地级市(300+)
- 县级区划(2800+)
贡献指南
欢迎提交Issue或Pull Request:
- Fork项目
- 创建分支(
git checkout -b feature/your-feature) - 提交更改(
git commit -am 'Add some feature') - 推送到分支(
git push origin feature/your-feature) - 创建Pull Request
许可证
版本说明
与 chinese_administrative_divisions 的关系
本项目是原 chinese_administrative_divisions 库的升级版本,主要改进包括:
| 特性 | 本版本 (china-division) | 旧版本 (chinese_administrative_divisions) |
|---|---|---|
| 包名称 | china-division | chinese_administrative_divisions |
|
| 查询接口 | 统一字符串输出格式 | 统一字符串输出格式 |
|
| 搜索算法 | 智能分级匹配 | 基础关键词匹配 |
| 数据更新 | 2023年最新行政区划 | 2023年最新行政区划 |
| 依赖关系 | 零依赖 | 零依赖 |
迁移指南
旧版本用户升级建议:
Python #旧版代码 from chinese_administrative_divisions import get_division
#新版替代方案 from china_division import search_division, get_division_info
#查询逻辑需要调整(新版始终返回字符串) result = search_division("朝阳区") # 返回 "110105:北京市朝阳区"
版本兼容性提示
本版本不保证与旧版API完全兼容,主要变更:
- 删除了一些旧版函数
- 统一了返回格式
- 优化了搜索算法
Metadata
Release files for china-division 2.0
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 | |
|---|---|---|---|---|
| china-division-2.0.tar.gz | 31.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| china_division-2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.9 kB
Release files / china-division-2.0.tar.gz
| Download URL | china-division-2.0.tar.gz |
|---|---|
| Size | 31.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4fad2b9627dba3eb5c14f460fa2313f50994e9d961b4448f4e33ebb66ca89a33
|
|
BLAKE2b-256 checksum How to use checksums |
8923ec2f32d54aff431bf2d642a7665237d24e9de5e2e61c6fca79df6dd4e89a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.8
|
Release files / china_division-2.0-py3-none-any.whl
| Download URL | china_division-2.0-py3-none-any.whl |
|---|---|
| Size | 31.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d98cfc859efe30480b0f00735ffcfe6883865a497a029a0847144c3e2adb368
|
|
BLAKE2b-256 checksum How to use checksums |
46afea4accb5fdab4b6fb6e031f853e9fef533180d98e79f70b960c11df9c7a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.8
|
Security for china-division 2.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.