Skip to main content

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

Release files for allowances-api 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for allowances-api 0.1.0
File Size Uploaded
allowances_api-0.1.0.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for allowances-api 0.1.0
File Interpreter ABI Platform
allowances_api-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / allowances_api-0.1.0.tar.gz

Download URL allowances_api-0.1.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c4822fd798385e3ae79f8509c0d234f884258d56acb063f4d1138a9547ead820
BLAKE2b-256 checksum
How to use checksums
4c9d966df36ffc8681abfc70a072981718abbdfe9d2868e878c21221245553b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release files / allowances_api-0.1.0-py3-none-any.whl

Download URL allowances_api-0.1.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9070785d5ff42dc955db3486df04fffe9247466d1eaff2e7cf09d4de0375b0d1
BLAKE2b-256 checksum
How to use checksums
ced3bab3a941e2322607f19ee05a21d93e320c9a8322ae528c6372ef842d2dab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page