A library to check for existing obligations from KAT Bulgaria
Project description
Summary
This library allows you to check if you have fines from KAT Bulgaria programatically.
The code here is a simple wrapper around the API, providing you with error validation and type safety.
It does NOT save or log your data anywhere and it works with a single API endpoint.
The reason this library is needed is because the government website is highly unstable and often throws random errors and Timeouts. This library handles all known bad responses (as of the time of writing) and provides a meaningful error message and an error code for every request.
If you like my work, please consider donating
Installation
pip install kat_bulgaria
Example usage:
import asyncio
from kat_bulgaria.kat_api_client import (
KatApiClient, KatError, KatErrorType
)
EGN = "0011223344"
LICENSE_NUMBER = "123456789"
async def sample_code():
"""Validates credentials"""
try:
# Validates EGN and Driver License Number locally and with the API.
is_valid = await KatApiClient().validate_credentials(EGN, LICENSE_NUMBER)
print(f"Valid: {is_valid}\n")
# Checks if a person has obligations, returns true or false.
obligations = await KatApiClient().get_obligations(EGN, LICENSE_NUMBER)
print(f"Obligation Count: {len(obligations)}\n")
print(f"Raw: {obligations}\n")
except KatError as err:
# Code should throw only KatError.
# Open an issue if you encounter another exception type.
print(f"Error Type: {err.error_type}\n")
print(f"Error Message: {err.error_message}")
if err.error_type in (
# Regex validation for EGN failed.
KatErrorType.VALIDATION_EGN_INVALID,
# Regex validation for Driving License failed.
KatErrorType.VALIDATION_LICENSE_INVALID,
# KAT API returned an error because the EGN/License combination was not found.
KatErrorType.VALIDATION_USER_NOT_FOUND_ONLINE
):
print("Invalid user input")
if err.error_type in (
# KAT API is slow. Happens couple of times per day.
# Retry or wait for some time to pass.
KatErrorType.API_TIMEOUT,
# KAT API has pooped its pants and is unable to do anything.
# That happens sometimes, either retry or wait for a bit.
KatErrorType.API_ERROR_READING_DATA,
# KAT API returned a non-200 status code. Should never happen.
# If it happens - open an issue and attach the response of the body.
KatErrorType.API_UNKNOWN_ERROR,
# KAT API returned response with a new schema.
# Indicates the API has been updated and I should update this package.
# Open an issue if you encounter this.
KatErrorType.API_INVALID_SCHEMA,
):
print("Unable to connect to KAT API")
# Run the async function
asyncio.run(sample_code())
Known raw API responses:
You can find sample API responses in /tests/fixtures.
I also document all sample responses in this issue for clarity.
If you have any fines, please add a comment to the issue above with the full API response.
You can get it by copying the url below and replacing EGN_GOES_HERE and LICENSE_GOES_HERE with your own data, then loading it in a browser.
Feel free to remove any personal data in the strings, but try not to modify the json structure.
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 kat_bulgaria-1.0.1.tar.gz.
File metadata
- Download URL: kat_bulgaria-1.0.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0130f5dd53f5f0c661d0dc1f0a8855a1283579294fa23f105a508c9f27791003
|
|
| MD5 |
c8a1b769c144f7db7fedd6e2759f389b
|
|
| BLAKE2b-256 |
6e36c8d2b21a28f81f5dfe6f80859465aafd352a48abc50e91e9fe1a0be95732
|
Provenance
The following attestation bundles were made for kat_bulgaria-1.0.1.tar.gz:
Publisher:
on-release-publish.yml on Nedevski/py_kat_bulgaria
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kat_bulgaria-1.0.1.tar.gz -
Subject digest:
0130f5dd53f5f0c661d0dc1f0a8855a1283579294fa23f105a508c9f27791003 - Sigstore transparency entry: 173765652
- Sigstore integration time:
-
Permalink:
Nedevski/py_kat_bulgaria@ace44c241fd716c18d910006718a12e0b2adb758 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Nedevski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-publish.yml@ace44c241fd716c18d910006718a12e0b2adb758 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kat_bulgaria-1.0.1-py3-none-any.whl.
File metadata
- Download URL: kat_bulgaria-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d8ad8ebd255a6e2ce5592a50bbd22f2649c371d4ff213c887a0f3353b6ffa2a
|
|
| MD5 |
aeffc49777a612f35cd5a825211ef062
|
|
| BLAKE2b-256 |
26b5384df5e6826224ded132b73e043f20b7877a1b764091d7985f44cbc5c896
|
Provenance
The following attestation bundles were made for kat_bulgaria-1.0.1-py3-none-any.whl:
Publisher:
on-release-publish.yml on Nedevski/py_kat_bulgaria
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kat_bulgaria-1.0.1-py3-none-any.whl -
Subject digest:
5d8ad8ebd255a6e2ce5592a50bbd22f2649c371d4ff213c887a0f3353b6ffa2a - Sigstore transparency entry: 173765655
- Sigstore integration time:
-
Permalink:
Nedevski/py_kat_bulgaria@ace44c241fd716c18d910006718a12e0b2adb758 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Nedevski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-publish.yml@ace44c241fd716c18d910006718a12e0b2adb758 -
Trigger Event:
release
-
Statement type: