Skip to main content

Bank Region Query

A Python package for querying bank region codes and names.

Installation

pip install bank-region-query

Usage

Bank name matching

Every API/CLI entry point that takes a bank name matches it as a string against each bank's canonical name and 别称 before querying. Nothing is derived or invented: the 别称 are taken verbatim from data/bank_aliases.json, generated from balance.xlsx (sheet 银行缩写) by scripts/build_bank_aliases.py. Comparison ignores whitespace, full-width/half-width and letter case.

  • a 别称 (工行, icbc, cmb) must match exactly — treating pinyin abbreviations as substrings would collide on shared prefixes (cmb ⊂ cmbc);
  • CJK names additionally match by containment in both directions: 农业银行 ⊂ 中国农业银行, and 中国农业银行北京分行 ⊃ 中国农业银行.

The number of matching banks then decides:

matches result
exactly 1 used directly
0 fail, message asks for a re-query
2–3 fail in script/API mode; interactive mode shows a menu to pick one
> 3 (MAX_CHOICES) fail, message asks for a more specific name
query.resolve_bank_name("icbc")        # '中国工商银行'
query.resolve_bank_name("建行")         # '建设银行'
query.resolve_bank_name("中信")         # '中信银行'   (containment)
query.resolve_bank_name("cmb")         # '招商银行'
query.resolve_bank_name("平安银行")      # None — matches no bank
query.resolve_bank_name("商银行")        # None — matches 3 banks
query.match_banks("商银行")             # ['中国工商银行', '招商银行', '浙商银行']
query.resolve_bank("商银行").message    # "... Please re-query with one of them: 1. ... 2. ... 3. ..."
query.list_aliases("工行").data        # ['icbc', '工商银行', '工行']

One deliberate refusal: an input carrying a parenthesised qualifier is never matched, because 中国建设银行(亚洲) is a separate entity rather than a spelling of 建设银行. It fails with a re-query message like any non-match.

Regenerate the 别称 table after editing the workbook:

python scripts/build_bank_aliases.py ~/Documents/balance.xlsx

Python API

from bank_region_query import BankRegionQuery

# Initialize
query = BankRegionQuery()

# Get region code by bank and region
result = query.get_region_code("中国农业银行", "北京市")
print(result.data)  # "001"

# Aliases work here too
result = query.get_region_code("农行", "北京市")
print(result.data)  # "001"

# Get region name by bank and code
result = query.get_region_by_code("中国农业银行", "001")
print(result.data)  # "北京市"

# Search by region across all banks
result = query.search_by_region("北京市")
print(result.data)  # {"中国农业银行": "001", ...}

# List all banks
banks = query.list_banks()
print(banks)  # ["中国农业银行", ...]

# Get statistics
stats = query.get_statistics()
print(stats)

Command Line Interface

# Get region code
bank-query code -b "中国农业银行" -r "北京市"
bank-query code -b "农行" -r "北京市"          # 别称

# Resolve a name to the canonical bank name
bank-query resolve -b "icbc"

# List known 别称
bank-query list aliases
bank-query list aliases -b "工行"

# Interactive mode shows a menu when a name matches 2-3 banks
bank-query interactive

# Get region name
bank-query region -b "中国农业银行" -c "001"

# Search by region
bank-query search --region "北京市"

# Search by code
bank-query search --code "001"

# List all banks
bank-query list banks

# List regions for a bank
bank-query list regions -b "中国农业银行"

# List codes for a bank
bank-query list codes -b "中国农业银行"

# Show statistics
bank-query stats

# Export data
bank-query export -o output.json

# Interactive mode
bank-query interactive

# JSON output
bank-query code -b "中国农业银行" -r "北京市" -f json

License

MIT

Metadata

Release files for bank-region-query 1.2.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 bank-region-query 1.2.0
File Size Uploaded Provenance
bank_region_query-1.2.0.tar.gz 57.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bank-region-query 1.2.0
File Interpreter ABI Platform
bank_region_query-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 113.8 kB

Release files / bank_region_query-1.2.0.tar.gz

Download URL bank_region_query-1.2.0.tar.gz
Size 57.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a48f74d02d1440f4669d86022c28d0ac0bbffe0b7d16eae9fded55b041a4deac
BLAKE2b-256 checksum
How to use checksums
34c8d91ae1bf0e549b6c1fcac09639010d47348720abfedfc335b6d9b31d08cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / bank_region_query-1.2.0-py3-none-any.whl

Download URL bank_region_query-1.2.0-py3-none-any.whl
Size 56.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80026e37b082daf73383bf5b083e676f956e601ab8058eaf093ffae6c60aec82
BLAKE2b-256 checksum
How to use checksums
a19bc63066b3831e34c1ab6ebe09279509b5d13dbc9127f11d4bda3dd41b18e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Security for bank-region-query 1.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.

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