Skip to main content

A Python package for simplified access to Kenya Revenue Authority (KRA) API

Project description

GavaConnect - Kenya Revenue Authority API Client

A Python package for simplified access to Kenya Revenue Authority (KRA) API. This package provides an easy-to-use interface for checking KRA PIN numbers and validating taxpayer information.

Features

  • 🔐 Secure authentication with KRA API
  • 📋 KRA PIN validation
  • 🆔 ID-based PIN lookup
  • 🏗️ Support for both sandbox and production environments
  • 📊 Tax obligation type enumeration
  • 🛡️ Error handling and logging

Installation

pip install gava-connect

Quick Start

1. Set up your environment variables

Create a .env file in your project directory:

PIN_CHECKER_CONSUMER_KEY=your_consumer_key_here
PIN_CHECKER_CONSUMER_SECRET=your_consumer_secret_here

2. Basic Usage

from gava_connect import KRAGavaConnect

# Initialize the client (sandbox environment)
kra_client = KRAGavaConnect(
    consumer_key="your_consumer_key",
    consumer_secret="your_consumer_secret",
    environment="sandbox"  # or "production"
)

# Check KRA PIN
result = kra_client.check_pin_kra_pin("A123456789")
print(result)

# Check PIN by ID number
result = kra_client.check_pin_by_id("12345678")
print(result)

API Reference

KRAGavaConnect

The main client class for interacting with the KRA API.

Constructor

KRAGavaConnect(consumer_key, consumer_secret, environment="sandbox")

Parameters:

  • consumer_key (str): Your KRA API consumer key
  • consumer_secret (str): Your KRA API consumer secret
  • environment (str): Environment to use ("sandbox" or "production")

Methods

check_pin_kra_pin(kra_pin_number)

Check if a KRA PIN is valid.

Parameters:

  • kra_pin_number (str): The KRA PIN number to validate

Returns:

  • dict: JSON response from the KRA API
check_pin_by_id(id_number)

Check KRA PIN using ID number.

Parameters:

  • id_number (str): The ID number to lookup

Returns:

  • dict: JSON response from the KRA API

TaxObligationType

Enumeration of tax obligation types supported by KRA.

Available Types

  • "4": Income Tax - Company
  • "7": Income Tax - PAYE
  • "9": Value Added Tax (VAT)
  • "22": Advance Tax
  • "6": Income Tax - Withholding
  • "32": Capital Gain Tax (CGT)
  • "29": VAT Withholding

Methods

get_obligation_type(code)

Get the description of a tax obligation type by its code.

get_obligation_code(description)

Get the code of a tax obligation type by its description.

Environment Configuration

The package supports two environments:

  • Sandbox: For testing and development
    • Base URL: https://sbx.kra.go.ke
  • Production: For live applications
    • Base URL: https://api.kra.go.ke

Error Handling

The package includes comprehensive error handling:

  • Invalid environment specification
  • Missing or invalid credentials
  • API authentication failures
  • Network request errors

Logging

The package uses Python's built-in logging module. Logs are set to INFO level by default.

Examples

Complete Example

import os
from dotenv import load_dotenv
from gava_connect import KRAGavaConnect, TaxObligationType

# Load environment variables
load_dotenv()

# Initialize client
kra_client = KRAGavaConnect(
    consumer_key=os.getenv("PIN_CHECKER_CONSUMER_KEY"),
    consumer_secret=os.getenv("PIN_CHECKER_CONSUMER_SECRET"),
    environment="sandbox"
)

# Check a KRA PIN
try:
    result = kra_client.check_pin_kra_pin("A123456789")
    print("PIN Check Result:", result)
except Exception as e:
    print(f"Error checking PIN: {e}")

# Get tax obligation type description
obligation_desc = TaxObligationType.get_obligation_type("9")
print(f"Tax obligation 9: {obligation_desc}")  # Output: Value Added Tax (VAT)

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, please open an issue on the GitHub repository or contact the maintainers.

Disclaimer

This package is not officially affiliated with the Kenya Revenue Authority. Please ensure you comply with KRA's terms of service and API usage guidelines.

KRA-GAVA-Connect

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

gava_connect-1.0.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

gava_connect-1.0.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file gava_connect-1.0.0.tar.gz.

File metadata

  • Download URL: gava_connect-1.0.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for gava_connect-1.0.0.tar.gz
Algorithm Hash digest
SHA256 79d02ff25dcf369f2e348e2cdd8ae3c642f01ebde85d29816f25e4847617bcc3
MD5 0f1f43898c8031d51c65f98a8e15fd35
BLAKE2b-256 4b89e97db772bf4994d7523471996baab914368db4461b09204e96633e564891

See more details on using hashes here.

File details

Details for the file gava_connect-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: gava_connect-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for gava_connect-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 721f992d697acd35ced2756f85c2845f055a447ee6b7dd895162fe3637be4277
MD5 a85b13f92b4edc4c184da2a337738e66
BLAKE2b-256 aaeba2cbb6a60116640fe1989e1dbfb0fc760b261f2d7d72d3d499d3b63f19f8

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