Skip to main content

中国行政区划查询工具

Project description

China Division 中国行政区划查询工具

PyPI version Python versions

一个高效查询中国行政区划的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:

  1. Fork项目
  2. 创建分支(git checkout -b feature/your-feature)
  3. 提交更改(git commit -am 'Add some feature')
  4. 推送到分支(git push origin feature/your-feature)
  5. 创建Pull Request

许可证

MIT License

版本说明

与 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完全兼容,主要变更:

  • 删除了一些旧版函数
  • 统一了返回格式
  • 优化了搜索算法

Project details


Release history Release notifications | RSS feed

This version

2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

china-division-2.0.tar.gz (31.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

china_division-2.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file china-division-2.0.tar.gz.

File metadata

  • Download URL: china-division-2.0.tar.gz
  • Upload date:
  • Size: 31.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.8

File hashes

Hashes for china-division-2.0.tar.gz
Algorithm Hash digest
SHA256 4fad2b9627dba3eb5c14f460fa2313f50994e9d961b4448f4e33ebb66ca89a33
MD5 81aea49053354c0437f050678048552f
BLAKE2b-256 8923ec2f32d54aff431bf2d642a7665237d24e9de5e2e61c6fca79df6dd4e89a

See more details on using hashes here.

File details

Details for the file china_division-2.0-py3-none-any.whl.

File metadata

  • Download URL: china_division-2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.8

File hashes

Hashes for china_division-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d98cfc859efe30480b0f00735ffcfe6883865a497a029a0847144c3e2adb368
MD5 fc69e1e4bff719a746bb0fb764c3df76
BLAKE2b-256 46afea4accb5fdab4b6fb6e031f853e9fef533180d98e79f70b960c11df9c7a4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page