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.24.tar.gz (601.3 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.24-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: employment_hero_sdk-0.1.24.tar.gz
  • Upload date:
  • Size: 601.3 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.24.tar.gz
Algorithm Hash digest
SHA256 a2dbb739b6ce98fb86742739f03a36844b7630e2b3d2088bae049348821355a3
MD5 ce5ce6b95479e840bab716259cd09745
BLAKE2b-256 70fd94740d46f98a17150b71317ee79a8b1a405103665c160513160f2a562157

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for employment_hero_sdk-0.1.24-py3-none-any.whl
Algorithm Hash digest
SHA256 64fc6929873c17e6734c8789bda1dae486091117988139ecff72b50b1f1e52ff
MD5 7345658a3721e83eee3bdb7cdcbdec85
BLAKE2b-256 1f0f18c726413ff9bc8f0a0557a0825d7a3c5914f187ff0485fded1520b11eca

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