SDKs & Client Libraries
Official client libraries make it easy to integrate the AfroTools API into your application. Available for JavaScript, Python, PHP, and more.
Available SDKs
🔥
JavaScript / Node.js
npm install afrotools
🐍
Python
pip install afrotools
🔮
PHP
composer require afrotools/sdk
⚡
REST API
cURL / Any HTTP client
JavaScript / Node.js
Installation
Install via npm or use the CDN for browser environments:
Client Methods
| Method | Description |
|---|---|
client.tax.calculate(params) | Calculate tax (POST /api/tax) |
client.tax.countries() | List supported countries (GET /api/tax) |
client.tax.country(code) | Get country info (GET /api/tax?country=XX) |
client.forex.latest(params) | Get exchange rate (GET /api/forex) |
client.fuel.prices(country?) | Get fuel prices (GET /api/fuel) |
client.rates.get(country?) | Get central bank rates (GET /api/rates) |
client.vat.calculate(params) | Calculate VAT (POST /api/vat) |
Python
Installation
Install via pip. Requires Python 3.7 or later.
Client Methods
| Method | Description |
|---|---|
client.tax.calculate(**kwargs) | Calculate tax |
client.tax.countries() | List countries |
client.forex.latest(from_currency, to) | Get exchange rate |
client.fuel.prices(country=None) | Get fuel prices |
client.rates.get(country=None) | Get central bank rates |
client.vat.calculate(**kwargs) | Calculate VAT |
PHP
Installation
Install via Composer. Requires PHP 7.4 or later with the cURL extension.
Want an SDK in another language? The AfroTools API is a standard REST API — any HTTP client works. See our authentication guide for raw HTTP examples in cURL and more.
JavaScript / Node.js
// Installation
npm install afrotools
// Or use CDN in browser
<script src="https://cdn.afrotools.com/sdk/v1/afrotools.min.js"></script>
// Usage
const AfroTools = require("afrotools");
const client = new AfroTools("afro_live_your_key");
// Calculate Nigerian income tax
const tax = await client.tax.calculate({
country: "NG",
amount: 500000,
type: "income",
period: "monthly"
});
console.log(tax.data.net_amount); // 381600
// Get forex rate
const fx = await client.forex.latest({
from: "USD", to: "NGN"
});
console.log(fx.data.rate); // 1580.25
// Get fuel prices
const fuel = await client.fuel.prices("NG");
console.log(fuel.data.fuels.petrol.price); // 897
// Calculate VAT
const vat = await client.vat.calculate({
country: "NG",
amount: 10000,
mode: "exclusive"
});
console.log(vat.data.gross_amount); // 10750
Python
# Installation
pip install afrotools
# Usage
from afrotools import AfroTools
client = AfroTools("afro_live_your_key")
# Calculate tax
tax = client.tax.calculate(
country="NG",
amount=500000,
type="income",
period="monthly"
)
print(tax["data"]["net_amount"]) # 381600
# Get forex rate
fx = client.forex.latest(
from_currency="USD", to="NGN"
)
print(fx["data"]["rate"]) # 1580.25
# Get central bank rates
rates = client.rates.get(country="KE")
print(rates["data"]["policy_rate"]) # 12.00
PHP
// Installation
composer require afrotools/sdk
// Usage
use AfroTools\Client;
$client = new Client("afro_live_your_key");
// Calculate tax
$tax = $client->tax->calculate([
"country" => "NG",
"amount" => 500000,
"type" => "income"
]);
echo $tax["data"]["net_amount"]; // 381600
// Get forex rate
$fx = $client->forex->latest([
"from" => "USD",
"to" => "NGN"
]);
echo $fx["data"]["rate"]; // 1580.25