Skip to main content

A-Share Code Converter

a-share-code-converter is a lightweight Python utility that helps you normalize and convert Chinese A-share stock codes between various formats. It supports:

  • Conversion to pure integer codes (e.g., 600519)
  • Conversion to zero-padded string codes (e.g., "600519")
  • Conversion to suffixed formats indicating exchanges (e.g., "600519.SH")

The converter supports multiple input types, including:

  • Python list
  • NumPy arrays
  • pandas.Series
  • polars.Series

📦 Installation

pip install a-share-code-converter

🚀 Usage

The CodeConverter class provides the following key methods:

1. CodeConverter.to_int(codes)

Converts various code formats (e.g. "600519.SH", "000001", 430047) into pure 6-digit integers.

  • ✅ Strips suffixes like .SH, .SZ, .BJ
  • ✅ Works with list, numpy.ndarray, pandas.Series, polars.Series
from a_share_code_converter import CodeConverter

codes = ["600519", "000001.SZ", "430047.BJ", 2415]

CodeConverter.to_int(codes)
# Output: [600519, 1, 430047, 2415]

2. CodeConverter.to_str(codes)

Converts input to zero-padded 6-digit string format without any suffix.

✅ Ensures all codes are 6-character strings like '000001', '600519'

CodeConverter.to_str(codes)
# Output: ['600519', '000001', '430047', '002415']

3. CodeConverter.to_suffix(codes)

Converts codes to full format with market suffix, e.g., '600519.SH'.

  • ✅ Based on numeric code ranges:

    • .SZ: 000000–399999

    • .SH: 600000–699999

    • .BJ: 400000–499999, 800000–899999

CodeConverter.to_suffix(codes)
# Output: ['600519.SH', '000001.SZ', '430047.BJ', '002415.SZ']

4. CodeConverter.convert(codes, to)

A unified entry point to perform conversion. Choose target format via to parameter:

to value Result
'int' Integer codes (int or np.int64)
'str' 6-digit zero-padded string codes
'suffix' 6-digit string with .SH/.SZ/.BJ
CodeConverter.convert(codes, to='int')
# Output: [600519, 1, 430047, 2415]

CodeConverter.convert(codes, to='str')
# Output: ['600519', '000001', '430047', '002415']

CodeConverter.convert(codes, to='suffix')
# Output: ['600519.SH', '000001.SZ', '430047.BJ', '002415.SZ']

🧪 Supported Input Types

  • list[str | int | float]

  • numpy.ndarray

  • pandas.Series

  • polars.Series

All methods will preserve the original type (e.g., return a pandas.Series if input is a pandas.Series).

Metadata

Release files for a-share-code-converter 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for a-share-code-converter 0.2.2
File Size Uploaded Provenance Actions
a-share-code-converter-0.2.2.tar.gz 5.5 kB Without provenance Details for a-share-code-converter-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for a-share-code-converter 0.2.2
File Interpreter ABI Platform Actions
a_share_code_converter-0.2.2-py3-none-any.whl Python 3 none any Details for a_share_code_converter-0.2.2-py3-none-any.whl

Total release size: 11.7 kB

Release files / a-share-code-converter-0.2.2.tar.gz

Download URL a-share-code-converter-0.2.2.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
27881776f5892b8fcca00c46366c2e5f60d0e5d0b52200de0291e24547e43c50
BLAKE2b-256 checksum
How to use checksums
8cfc0d8dd73e25a7822a2e51a6c0a45ede33c38c33f7b7c1581031704d673157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.7

Release files / a_share_code_converter-0.2.2-py3-none-any.whl

Download URL a_share_code_converter-0.2.2-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c232e8715dae1a8e5e50a7f5de4252106e0a6cb3f691dccd0bd32bb3f56adc0c
BLAKE2b-256 checksum
How to use checksums
d8b7b110433898335dd1a13ddd682f285c264a0caa1bbbbf965ed37ba26646fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.7

Security for a-share-code-converter 0.2.2

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