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.1.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.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gava_connect-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 df9dfde5c3c995e33793c4a7a12f21e498d98e1e07ccc6d8064c46a9fcd111dc
MD5 b7a27edbb4f09f35840aeb2e4bedb816
BLAKE2b-256 bf6152728f84efcc82977a8c3a0cd9f71bbff2d83641678310c0a2c164ecbeb8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gava_connect-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 003164b88b53cd3a0a839af506ef70e8717555b99329c20f6877d878b9df0193
MD5 6c0bc067800a2f2ecc4899de69e91d5e
BLAKE2b-256 f4692d0f9a668b9b378feb7428c6733538f770910aa9d76867521d7f5b6632c0

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