Skip to main content

A library to check for existing obligations from KAT Bulgaria

Project description

Summary

PyPI Link Last release PyPI License PyPI Downloads Code size

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.

Installation

pip install kat_bulgaria

Example:

from kat_bulgaria.obligations import (
    KatApi, 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 KatApi().validate_credentials(EGN, LICENSE_NUMBER)
        print(f"Valid: {is_valid}\n")

        # Checks if a person has obligations, returns true or false.
        obligations = await api.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}")

        match err.error_type:
            case KatErrorType.VALIDATION_EGN_INVALID:
                # Regex validation for EGN failed.

            case KatErrorType.VALIDATION_LICENSE_INVALID:
                # Regex validation for Driving License failed.

            case KatErrorType.VALIDATION_USER_NOT_FOUND_ONLINE:
                # KAT API returned an error because the EGN/License combination was not found.

            case KatErrorType.API_TIMEOUT:
                # KAT API is slow. Happens couple of times per day.
                # Retry or wait for some time to pass.

            case KatErrorType.API_ERROR_READING_DATA:
                # KAT API has pooped its pants and is unable to do anything.
                # That happens sometimes, either retry or wait for a bit.

            case KatErrorType.API_UNKNOWN_ERROR:
                # KAT API returned a non-200 status code. Should never happen.
                # If it happens - open an issue and attach the response of the body.

            case KatErrorType.API_INVALID_SCHEMA:
                # 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.

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.

https://e-uslugi.mvr.bg/api/Obligations/AND?obligatedPersonType=1&additinalDataForObligatedPersonType=1&mode=1&obligedPersonIdent=EGN_GOES_HERE&drivingLicenceNumber=LICENSE_GOES_HERE

Feel free to remove any personal data in the strings, but try not to modify the json structure.

Project details


Download files

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

Source Distribution

kat_bulgaria-0.7.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

kat_bulgaria-0.7.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file kat_bulgaria-0.7.0.tar.gz.

File metadata

  • Download URL: kat_bulgaria-0.7.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for kat_bulgaria-0.7.0.tar.gz
Algorithm Hash digest
SHA256 e880f326eb41ad29d5632332632d800d1124d53d731f8fa8a77c4d921c9ce0e1
MD5 be45b9a98127ef1a389fa1c4f189c86f
BLAKE2b-256 776acf5fea77aa130caa796d88a2534089cff8b5e5d484369e2249fff67f1881

See more details on using hashes here.

File details

Details for the file kat_bulgaria-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: kat_bulgaria-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for kat_bulgaria-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d73efe0b2a0742e261f6104c64ef4fee467eb513ea9343793887a64acc01a7e
MD5 19b552e50ebf416082c46a591d18206a
BLAKE2b-256 e9deb04d49b15efc6481b90c90d1d8e2719b4db26b6f03ebc5d86e30c5889c18

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