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.company.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.1.1.tar.gz (5.9 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.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tria_hr_api-1.1.1.tar.gz
  • Upload date:
  • Size: 5.9 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.1.tar.gz
Algorithm Hash digest
SHA256 babefef8af987a727d252c3a776d35ea4eb4f052299ef9dc93c4637dcfcb7241
MD5 60f463535d313d36f23ecc8bfc5522f5
BLAKE2b-256 8b48a29f3ff40c57912528727246fe29094400d773c59312db06dbf949ca8168

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tria_hr_api-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b0e279469c3773f902d90cff22346c644123e17ff1038b9f9d8d4a0d2fe50812
MD5 ff4a887dd3427db98740c5ec79a71250
BLAKE2b-256 3b0274d48a438cfadd865f388223f95fb95b8882d01e6c97186349b18053c19f

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