Official Python SDK for the Allowances API
Project description
Allowances API Python SDK
The official Python client for Allowances API, a normalized API for U.S. government travel and overseas compensation data.
The API brings together rates published by three different government sources:
- DSSR — overseas post allowance (COLA), hardship differential, danger pay, education allowance, living quarters allowance, and foreign per diem.
- DTMO — military per diem for CONUS and OCONUS locations.
- GSA — civilian CONUS per diem, mileage reimbursement, and Fleet vehicle leasing rates.
This SDK handles API-key authentication, URL construction, parameter serialization, response decoding, and useful Python exceptions. It is useful for travel platforms, expense systems, payroll and mobility tools, government contractors, and internal applications that need current or historical allowance data without maintaining scrapers for several unrelated sources.
Installation
pip install allowances-api
Python 3.9 or newer is required.
Authentication
Create an API key at allowancesapi.com, then provide it directly:
from allowances_api import AllowancesClient
client = AllowancesClient("ak_live_your_key")
For applications, keeping the key in an environment variable is preferable. The client will find your api key if you set it explicitely as ALLOWANCES_API_KEY.
export ALLOWANCES_API_KEY="ak_live_your_key"
from allowances_api import AllowancesClient
client = AllowancesClient() # reads ALLOWANCES_API_KEY
Every request sends the key in the API's X-API-Key header. Do not embed a secret API key in browser or mobile client code.
Quick start
Use the client as a context manager so its connection pool is closed automatically:
from datetime import date
from allowances_api import AllowancesClient
with AllowancesClient() as client:
# Overseas allowances for Nairobi
kenya = client.dssr.allowances_by_location(
"KE",
"Nairobi",
date=date.today(),
type=["cola", "hardship", "danger_pay"],
)
# Military OCONUS per diem
australia = client.dtmo.perdiem_oconus("AU", query="Adelaide")
# Civilian CONUS per diem
albany = client.gsa.perdiem_by_state("NY", location="Albany")
Responses are returned as decoded dictionaries or lists, matching the documented JSON response exactly.
Common use cases
Look up an overseas post allowance and calculate COLA
rates = client.dssr.allowances_by_postcode("BE", "10112", types=["cola"])
estimate = client.dssr.calculate_cola(
"10112",
family_size=4,
base_salary=100_000,
)
print(estimate["annual_cola"], estimate["biweekly_cola"])
Retrieve per diem by source
# Department of State foreign per diem
dssr = client.dssr.perdiem_by_location("KE", "Nairobi")
# Defense Travel Management Office military rates
dtmo = client.dtmo.perdiem_conus("US-CO", query="Aspen")
# General Services Administration civilian rates
gsa = client.gsa.perdiem_by_zipcode("12207")
Mileage and GSA Fleet rates
mileage = client.gsa.mileage(mileage_type="automobile")
fleet = client.gsa.vehicle_rates("standard", "10B", year=2026)
Browse locations
countries = client.dssr.countries(query="United")
dssr_locations = client.dssr.country_locations("DE")
dtmo_locations = client.dtmo.locations_oconus("AU", location="Sydney")
states = client.gsa.states()
destinations = client.gsa.destinations(limit=50)
Errors
The SDK maps common status codes to specific exceptions:
from allowances_api import ForbiddenError, NotFoundError, RateLimitError
try:
result = client.dssr.perdiem("XX")
except NotFoundError as exc:
print(exc.status_code, exc.message, exc.request_id)
except ForbiddenError:
print("This request is not included in the current plan")
except RateLimitError:
print("Request limit reached")
Available exception classes are AuthenticationError, ForbiddenError, NotFoundError, ValidationError, RateLimitError, TransportError, and the base AllowancesAPIError.
Configuration
Use a different endpoint or timeout for local development and testing:
client = AllowancesClient(
"test-key",
base_url="http://localhost:8000/v1",
timeout=10,
)
An existing httpx.Client can be injected for custom transports, proxies, telemetry, or testing:
import httpx
from allowances_api import AllowancesClient
transport = httpx.HTTPTransport(retries=2)
http = httpx.Client(base_url="https://api.allowancesapi.com/v1", transport=transport)
client = AllowancesClient("ak_live_your_key", http_client=http)
When injecting a client, its lifecycle remains owned by the caller.
Endpoint mapping
SDK methods follow the API's three source groups:
client.dssr: allowances, per diem, COLA calculator, countries, and locations.client.dtmo: CONUS/OCONUS per diem, search, and locations.client.gsa: destination/state/ZIP per diem, ZIP and county metadata, mileage, and vehicle rates.
See the complete API documentation for response fields, plan limits, and data-source details.
Development and publishing
python -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'
pytest
ruff check .
python -m build
twine check dist/*
Publish a release after updating the version in pyproject.toml and src/allowances_api/__init__.py:
twine upload dist/*
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file allowances_api-0.1.0.tar.gz.
File metadata
- Download URL: allowances_api-0.1.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4822fd798385e3ae79f8509c0d234f884258d56acb063f4d1138a9547ead820
|
|
| MD5 |
6b4367ebce1012e5de01ae75dcbe758b
|
|
| BLAKE2b-256 |
4c9d966df36ffc8681abfc70a072981718abbdfe9d2868e878c21221245553b2
|
File details
Details for the file allowances_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: allowances_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9070785d5ff42dc955db3486df04fffe9247466d1eaff2e7cf09d4de0375b0d1
|
|
| MD5 |
b9a7892c99323b1e01788150b1626876
|
|
| BLAKE2b-256 |
ced3bab3a941e2322607f19ee05a21d93e320c9a8322ae528c6372ef842d2dab
|