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 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.0.tar.gz (2.8 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.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tria_hr_api-1.0.0.tar.gz
  • Upload date:
  • Size: 2.8 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.0.tar.gz
Algorithm Hash digest
SHA256 f28b2e6a5e7ff1c8f016ddd4bb74df166d779931131780d45ad957fa6e404b92
MD5 99589aa463cb8bd5b45bfde40015b6d4
BLAKE2b-256 877a06c50f1ff20047de55e4f0db61a3394519a3d69d8567fa50d35e86547f4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tria_hr_api-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5033243dae6afcd9ead509e1696e7b073666a657831975ee7e520835581edab
MD5 c775edcc4953f6e83304212913e0740d
BLAKE2b-256 7a42f22f7a0f706a2a0d61241722524e0d16b347ea291749dd8918c16ca3bcd5

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