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 tria-hr-api

Configuration

You can initialize the client either directly or using a configuration file.

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')

Direct Initialization

from triahr import TriaHRAPI

api = TriaHRAPI(
    base_url="https://stage.decasport.triahr.com",
    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 Plan

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)

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
  • 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}")

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.0.1.tar.gz (5.2 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.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tria_hr_api-1.0.1.tar.gz
  • Upload date:
  • Size: 5.2 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.0.1.tar.gz
Algorithm Hash digest
SHA256 2e1da6b9f47fff4e99feb7b8121c986ac0caf5f955e6509decec6e371c4ad969
MD5 965727053669f7ab6cc0fdfbdd10a662
BLAKE2b-256 8c4e1c77a15642991df6ae8006f76164e6f268d76cdefd9f881fa118d06c761c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tria_hr_api-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a54ef6e5f392a61fd5313159af6468fed4c52ebd6eddcfae92454d650cab3004
MD5 26626cd7bc2423087618bc98db6f6b5d
BLAKE2b-256 bc1edfa07aec5726f949f3b901a5b69237a499e1738278f5a091c7f33d3160c2

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