Skip to main content

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

Metadata

Release files for tria-hr-api 1.1.2

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

Source distribution (sdist)

Source distribution for tria-hr-api 1.1.2
File Size Uploaded Provenance Actions
tria_hr_api-1.1.2.tar.gz 6.4 kB Without provenance Details for tria_hr_api-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tria-hr-api 1.1.2
File Interpreter ABI Platform Actions
tria_hr_api-1.1.2-py3-none-any.whl Python 3 none any Details for tria_hr_api-1.1.2-py3-none-any.whl

Total release size: 13.3 kB

Release files / tria_hr_api-1.1.2.tar.gz

Download URL tria_hr_api-1.1.2.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
94e1dadcd90c16485071f647b05e4c916e74b8ea5263f6bdf8c00e0fd8aca2a7
BLAKE2b-256 checksum
How to use checksums
a1d702d469e026cb3c58e1afa73bbf597881ea1ee22ab7578f480d76f402344f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.6

Release files / tria_hr_api-1.1.2-py3-none-any.whl

Download URL tria_hr_api-1.1.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e08d1d0646d1b6d9aa0e7b4e180650de5c6f388d284cca92b421cc2ffd327ca
BLAKE2b-256 checksum
How to use checksums
15bd68fd35e6083818bfe98d4ced49aa2839468fee785235163ccfb97e8bd89c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.6

Security for tria-hr-api 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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