Skip to main content

Efficiently interact with the Employment Hero/Key Pay API

Project description

Employment Hero SDK

PyPI version License: CC BY-NC 4.0

Simple, lightweight and efficient Python client wrapper for interacting with the Employment Hero/Key Pay API. It provides a consistent, chainable interface for both synchronous and asynchronous operations, making it easy to fetch, create, update, and delete resources....

Features

  • Simple, Chainable API: Navigate endpoints with intuitive chaining (e.g. client.business("biz123").employees.fetch("emp456")).
  • Synchronous and Asynchronous Support: Choose the mode that best fits your application's needs.
  • Built-in Pagination: Easily fetch all pages of data using built-in pagination methods.
  • Caching: Cache business listings to reduce unnecessary API calls.
  • Error Handling: Receive informative exceptions for API errors.
  • Throttling: Automatically handle rate limiting and backoff.

Installation

You can install the package directly from PyPI:

pip install employment-hero-sdk

Usage

Synchronous Example

from employment_hero_sdk import EmploymentHeroClient

# Initialize the client with your API key
client = EmploymentHeroClient(api_key="your_api_key")

# Retrieve all available businesses (cached)
businesses = client.business()  # Returns a list of Business objects
for biz in businesses:
    print(biz)

# Retrieve a specific business by ID
biz = client.business("business_id_123")

# Fetch an employee from a specific business
employee = biz.employee("employee_id_456")
print(f"Employee: {employee.full_name}")

Asynchronous Example

import asyncio
from employment_hero_sdk import EmploymentHeroClient

async def main():
    # Initialize the client with your API key
    client = EmploymentHeroClient(api_key="your_api_key")
    
    # Retrieve all available businesses asynchronously
    businesses = await client.business()  # Returns a list of Business objects
    for biz in businesses:
        print(biz)
    
    # Retrieve a specific business by ID asynchronously
    biz = await client.business("business_id_123")
    
    # Fetch an employee from the specific business asynchronously
    employee = await biz.employee("employee_id_456")
    print(f"Employee: {employee.full_name}")

asyncio.run(main())

Dynamic Paths

We also dynamically load paths if there isn't an api model for the path, which will return data if the path exists.

The data can be returned as a list of dictionaries or as a pandas DataFrame if dataframe=True is passed as a keyword argument.

import datetime
from employment_hero_sdk import EmploymentHeroClient

EMPLOYMENT_HERO_API_KEY = "api_key"

client = EmploymentHeroClient(api_key=EMPLOYMENT_HERO_API_KEY)

for business in client.business().values():
    print(business.show())
    for employee in business.employee():
        print(employee.show())
        opening_balances = employee.openingbalances() #/api/v2/business/{busness_id}/employee/{employee_id}/openingbalances is a valid path
        print(opening_balances)
        break

    # or snake case will split into a path e.g. report_birthday -> report/birthday?{kwargs}
    birthday_report = business.report_birthday(fromDate=datetime.date(day=1, month=1, year=2025), toDate=datetime.date.today())

    # or include dataframe=True to return a pandas dataframe
    timesheet_report_df = business.report_timesheet(
        dataframe=True,
        **{
            'request.fromDate': datetime.date(day=1, month=1, year=2025), 
            'request.toDate': datetime.date.today()
        }
    )

License

This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. You are free to use, share, and modify the software for non-commercial purposes only.

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

employment_hero_sdk-0.1.22.tar.gz (601.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

employment_hero_sdk-0.1.22-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file employment_hero_sdk-0.1.22.tar.gz.

File metadata

  • Download URL: employment_hero_sdk-0.1.22.tar.gz
  • Upload date:
  • Size: 601.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.3 Darwin/25.2.0

File hashes

Hashes for employment_hero_sdk-0.1.22.tar.gz
Algorithm Hash digest
SHA256 217311355cb5c9e781977357b53f5537fb3e98e99227ed46048c2f9930428848
MD5 13656202b501fc1154eb5bfc461a2684
BLAKE2b-256 2ed102e7c0b0c1bf5a3a61b9829e7ab9642eff19308ec6fb321a6dc904773d85

See more details on using hashes here.

File details

Details for the file employment_hero_sdk-0.1.22-py3-none-any.whl.

File metadata

File hashes

Hashes for employment_hero_sdk-0.1.22-py3-none-any.whl
Algorithm Hash digest
SHA256 f8838ca4b60d0d90b3f9d1e464c5b53b8b78e168a8581e5527fe28109a3a1a27
MD5 b19e4d2bb841f21c06dcd4a63c9557d9
BLAKE2b-256 ab8e3e7cee6f994a6e146ed00501819f28a7d1d19d415372c69c0a3a59583d60

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