Thai VAT tax ID lookup with 10/13-digit support (RD VATINFO)
Project description
Thai VAT tax ID lookup for the RD VATINFO service — smart, fast, async-ready
Source Code: https://github.com/RThaweewat/phasi-kit
PyPI: https://pypi.org/project/phasi-kit/
phasi-kit provides a simple, production-friendly client to query Thailand's Revenue Department VATINFO service. It auto-detects 10/13‑digit tax IDs, returns structured results, and supports high-performance async lookups.
Key Features
- Unified API: One
lookup()for 10/13‑digit IDs; smart multi-branch handling. - Async-ready:
lookup_async()plus an async client with pooling. - Response caching: Optional caching with TTL to reduce API calls (disabled by default).
- Robust: Retries with backoff, request coalescing, and clear errors.
- Clean parsing: Converts TIS‑620 HTML into typed
TaxInfoobjects. - Ergonomic results:
result.first,result.count, iterate branches,result.hq.
Requirements
- Python 3.10+
Installation
pip install phasi-kit
Using uv:
uv pip install phasi-kit
Example
Create a simple lookup:
from phasi_kit import lookup
result = lookup("0107555000023") # dashes/spaces also work
print(result.company_name)
print(result.count)
print(result.first.address)
# Output:
# บริษัท ซีพีเอฟ (ประเทศไทย) จำกัด (มหาชน)
# 10
# อาคาร ซี.พี.ทาวเวอร์ เลขที่ 313 ถนน สีลม ตำบล/แขวง สีลม อำเภอ/เขต บางรัก จังหวัด กรุงเทพมหานคร 10500
Multiple branches:
result = lookup("0107555000023") # CPF has many branches
# Iterate through branches
for info in result[:5]: # Show first 5
print(f"Branch {info.branch_no}: {info.company_name}")
# Output:
# Branch 0: บริษัท ซีพีเอฟ (ประเทศไทย) จำกัด (มหาชน)
# Branch 00001: บริษัท ซีพีเอฟ (ประเทศไทย) จำกัด (มหาชน)
# Branch 00002: บริษัท ซีพีเอฟ (ประเทศไทย) จำกัด (มหาชน)
# Branch 00003: บริษัท ซีพีเอฟ (ประเทศไทย) จำกัด (มหาชน)
# Branch 00004: บริษัท ซีพีเอฟ (ประเทศไทย) จำกัด (มหาชน)
Async lookup:
import asyncio
from phasi_kit import lookup_async
async def main():
res = await lookup_async("0105534038143")
print(res.first.company_name)
asyncio.run(main())
# Output:
# บริษัท พร็อสเพอร์สโตน จำกัด
Lookup with branch:
# Query specific branch
result = lookup("0107555000023", branch_no="00001")
print(f"Branch: {result.first.branch_no}")
print(f"Company: {result.first.company_name}")
print(f"Address: {result.first.address}")
# Output:
# Branch: 00001
# Company: บริษัท ซีพีเอฟ (ประเทศไทย) จำกัด (มหาชน)
# Address: เลขที่ 178 หมู่ที่ 4 ถนน พิษณุโลก-หล่มสัก ตำบล/แขวง สมอแข อำเภอ/เขต เมืองพิษณุโลก จังหวัด พิษณุโลก 65000
Validation helper:
from phasi_kit import validate_and_route_tax_id
v = validate_and_route_tax_id("0107-555-000023")
print(v.is_valid, v.tax_id_type, v.cleaned_id)
# Output:
# True 13 0107555000023
Caching
Response caching to reduce API calls (disabled by default):
# Enable with default 5-minute TTL
result = lookup("0107555000023", enable_cache=True)
# Custom TTL (10 minutes)
client = VATInfoClient(enable_cache=True, cache_ttl=600)
result1 = client.lookup_smart("0107555000023")
result2 = client.lookup_smart("0107555000023") # Uses cache
# Check cache stats
print(client.get_cache_stats())
# {'size': 1, 'hits': 1, 'misses': 1, 'hit_rate': '50.0%'}
# Clear cache if needed
client.clear_cache()
Environment
PHASI_VATINFO_URL: Override the default RD endpoint if needed.
License
Apache-2.0 (see LICENSE)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phasi_kit-0.2.2.tar.gz.
File metadata
- Download URL: phasi_kit-0.2.2.tar.gz
- Upload date:
- Size: 192.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
803e49c0470531cd6e0d4f620f9b71a68db5997770eef0d136cdf08028a84f68
|
|
| MD5 |
1f80473ee578d942fba6d275e3dbf66f
|
|
| BLAKE2b-256 |
8843ec8cf1c79e0768b2af3297715a1e3bca2930971f04da9712a8573b3b030b
|
File details
Details for the file phasi_kit-0.2.2-py3-none-any.whl.
File metadata
- Download URL: phasi_kit-0.2.2-py3-none-any.whl
- Upload date:
- Size: 33.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d369723d651c3a5534c9a5cdd6f64626306634cfebc5bc6c075d70c749a7fa6
|
|
| MD5 |
3064be24eca552639276176e1e9b3b2a
|
|
| BLAKE2b-256 |
f0c87e94d24fd8f81fa1bc842953c68eb01fa61217813c84793c2d454c960c85
|