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 keyconsumer_secret(str): Your KRA API consumer secretenvironment(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
- Base URL:
- Production: For live applications
- Base URL:
https://api.kra.go.ke
- Base URL:
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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- 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
Metadata
Release files for gava-connect 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gava_connect-1.0.1.tar.gz | 13.3 kB | Without provenance | Details for gava_connect-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gava_connect-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for gava_connect-1.0.1-py3-none-any.whl |
Total release size: 23.3 kB
Release files / gava_connect-1.0.1.tar.gz
| Download URL | gava_connect-1.0.1.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df9dfde5c3c995e33793c4a7a12f21e498d98e1e07ccc6d8064c46a9fcd111dc
|
|
BLAKE2b-256 checksum How to use checksums |
bf6152728f84efcc82977a8c3a0cd9f71bbff2d83641678310c0a2c164ecbeb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.23
|
Release files / gava_connect-1.0.1-py3-none-any.whl
| Download URL | gava_connect-1.0.1-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
003164b88b53cd3a0a839af506ef70e8717555b99329c20f6877d878b9df0193
|
|
BLAKE2b-256 checksum How to use checksums |
f4692d0f9a668b9b378feb7428c6733538f770910aa9d76867521d7f5b6632c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.23
|
Security for gava-connect 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.