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.23.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.23-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: employment_hero_sdk-0.1.23.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.23.tar.gz
Algorithm Hash digest
SHA256 785d3ff6e181fd4c2000a7bf96571aadc768997848ec9acb8d1ef65270f23cc8
MD5 58e19e8b55776c1cd3af58c84c945bc5
BLAKE2b-256 0ce67185fa87fdbfc324225a027e663d671bf450b5c8ca7f4feec9eed84fa9e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for employment_hero_sdk-0.1.23-py3-none-any.whl
Algorithm Hash digest
SHA256 b38906a1d8ffde6b7205b81d38b4886b4c0ecb11672ff08ff46a02a5c5e9d95c
MD5 cb55d95496926a0e19591a548b0093be
BLAKE2b-256 a3066b16a350f2d445897a9f631eb2689f3ed0ff0740ea10974bf70bf61e5a9c

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