Skip to main content

Python client for interacting with the Tria HR API

Project description

Tria HR API Client

A Python client for interacting with the Tria HR API. This library provides easy access to attendance, organization units, and company data.

Installation

pip install triahr-client

Configuration

You can initialize the client in three different ways:

1. Using Configuration File

Create a config.ini file:

[Environment]
stage = https://stage.company.triahr.com
prod = https://company.triahr.com

[OAuth]
client_id = your_client_id
client_secret = your_client_secret

Initialize the client:

from triahr import TriaHRAPI

# Initialize using config file (defaults to 'stage' environment)
api = TriaHRAPI.from_config()

# Or specify a different environment
api = TriaHRAPI.from_config(environment='prod')

2. Direct Initialization

from triahr import TriaHRAPI

api = TriaHRAPI(
    base_url="https://stage.company.triahr.com",
    client_id="your_client_id",
    client_secret="your_client_secret"
)

3. Using JSON Credentials

This is particularly useful when using the library in Databricks:

from triahr import TriaHRAPI
import json

# When using Databricks secrets
credentials = json.loads(dbutils.secrets.get(scope="tria_hr", key="credentials"))
api = TriaHRAPI.from_json(
    base_url="https://stage.company.triahr.com",
    credentials_json=credentials
)

Required JSON format for credentials:

{
    "client_id": "your_client_id",
    "client_secret": "your_client_secret"
}

Usage Examples

Test Connection

response = api.ping()
api.format_response(response)

Get Organization Units

# Get organization units for a specific company
org_units = api.organization_units(company_id="158")
api.format_response(org_units)

# Get attendance organization units
attendance_units = api.attendance_organization_units(company_id="158")
api.format_response(attendance_units)

Get Attendance Plans

# Get attendance plan for a single unit
attendance = api.attendance_plan(
    date_from="2024-01-01",
    date_to="2024-01-31",
    unit_id=123,
    mode="plan"  # or "reality" for published data
)
api.format_response(attendance)

# Get attendance plans for all units in a company
plans = api.attendance_plans(
    date_from="2024-01-01",
    date_to="2024-01-31",
    company_id="158",
    include_activated=True,     # include active units
    include_deactivated=False   # exclude deactivated units
)

Save Response to File

response = api.companies()
api.format_response(response, save_to_file="companies.json")

Custom API Requests

# Make a custom GET request
response = api.undefined_request(
    endpoint="/api/v1/custom-endpoint/",
    params={"param1": "value1"}
)

# Make a custom POST request
response = api.undefined_request(
    endpoint="/api/v1/custom-endpoint/",
    method="POST"
)

Available Methods

  • ping(): Test API connection
  • companies(): Get list of companies
  • organization_units(company_id): Get organization units for a company
  • attendance_organization_units(company_id): Get plannable attendance units
  • attendance_plan(date_from, date_to, ...): Get attendance plan data for a single unit
  • attendance_plans(date_from, date_to, company_id, ...): Get attendance plans for all units in a company
  • undefined_request(endpoint, method, params): Make custom API requests

Authentication

The client handles OAuth2 authentication automatically, including token refresh. You only need to provide the client ID and secret.

Error Handling

The client will raise requests.exceptions.HTTPError for any API errors. Handle these appropriately in your application:

try:
    response = api.companies()
except requests.exceptions.HTTPError as e:
    print(f"API error: {e}")

Requirements

  • Python ≥ 3.7
  • requests ≥ 2.25.0

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

tria_hr_api-1.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

tria_hr_api-1.1.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file tria_hr_api-1.1.2.tar.gz.

File metadata

  • Download URL: tria_hr_api-1.1.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for tria_hr_api-1.1.2.tar.gz
Algorithm Hash digest
SHA256 94e1dadcd90c16485071f647b05e4c916e74b8ea5263f6bdf8c00e0fd8aca2a7
MD5 db73e252f94c8f8f47d3b159e0e08efb
BLAKE2b-256 a1d702d469e026cb3c58e1afa73bbf597881ea1ee22ab7578f480d76f402344f

See more details on using hashes here.

File details

Details for the file tria_hr_api-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: tria_hr_api-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for tria_hr_api-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7e08d1d0646d1b6d9aa0e7b4e180650de5c6f388d284cca92b421cc2ffd327ca
MD5 f14510fb6a77827afb1123005d3c2c4e
BLAKE2b-256 15bd68fd35e6083818bfe98d4ced49aa2839468fee785235163ccfb97e8bd89c

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