hdforce
A Python package for accessing the Hawkin Dynamics API. Authentication management, pandas DataFrames, and simple one-liner data access.
Installation
Install hdforce from PyPI using pip.
Authentication
hdforce uses a flexible authentication system with environment variables, .env files, or direct token input.
Set Up Your Refresh Token
Store your Hawkin Dynamics Integration Key as the HD_REFRESH_TOKEN environment variable, in a .env file, or pass it directly.
Authenticate
Run AuthManager(region="Americas") to exchange your refresh token for an access token. The method is chosen via the authMethod parameter.
Start Querying
All Get*() functions use the active authentication automatically. Call GetTests() to start pulling data.
Quick Start
A complete, runnable script to get your first data.
Regional Endpoints
Set the region parameter in AuthManager() to match your organization's data residency.
| Region | Value | Base URL |
|---|---|---|
| Americas | "Americas" |
cloud.hawkindynamics.com |
| Europe | "Europe" |
eu.cloud.hawkindynamics.com |
| Asia-Pacific | "APAC" |
apac.cloud.hawkindynamics.com |
User Guide
In-depth tutorials covering environment setup, data retrieval, example workflows, and integrating hdforce into web applications.
Environment Setup
Before using hdforce, you can configure logging and authentication to suit your development workflow.
Event Logging
hdforce supports event logging for detailed function process output and debugging. Use LoggerConfig.Configuration() to customize the logging behavior at the start of your script or session.
Configuration options:
| Option | Description |
|---|---|
file | Stream logs to stdout (default) or create a log file |
level | Minimum log level to output (default: "warning") |
file_path | Custom file path (default: "root/hdforce.log") |
file_mode | Append to log file or overwrite each session |
Authentication with AuthManager
Use the AuthManager() function to authenticate with the Hawkin Dynamics API. The function supports three authentication methods to fit different environments.
Method 1: Environment Variables (default)
Store your refresh token as a system environment variable named HD_REFRESH_TOKEN. This is the simplest approach for local development.
Method 2: Environment File
Store variables in a .env file for more visible and dynamic interaction with auth variables.
Method 3: Manual Token
Pass the refresh token directly. Useful for password-protected applications where the token is provided at runtime and should not be stored.
Creating Environment Variables
For local development, storing your refresh token as a system environment variable keeps it secure and reusable across projects.
Windows
- Right-click the Start button and select System.
- Click Advanced system settings on the left sidebar.
- Click the Environment Variables... button.
- Under User variables, click New...
- Enter
HD_REFRESH_TOKENas the name and your token as the value. Click OK.
macOS
- Open Terminal (Applications → Utilities → Terminal).
- Edit your profile:
open -e ~/.zshrc(or~/.bash_profilefor Bash). - Add the line:
export HD_REFRESH_TOKEN='your_api_key_here' - Apply changes:
source ~/.zshrc
Verify Your Environment Variable
Getting Data
Once authenticated, hdforce provides functions to retrieve Hawkin-specific, organizational, and test data.
Hawkin-Specific Data
These functions return data about test types and metrics available in the Hawkin Dynamics system. Useful for understanding what data is available and building efficient queries.
| Function | Purpose |
|---|---|
GetTypes() | Get test type names and IDs for all test types in the system |
GetMetrics() | Get all metrics per test type: canonical ID, name, metric ID, label, units, description |
Organization Data
Every organization has unique entities with their own IDs. Retrieve these to use as filters when pulling test data.
| Function | Purpose |
|---|---|
GetAthletes() | Get all athletes. Set includeInactive=True to include inactive athletes |
GetTeams() | Get team names and IDs for all teams in the organization |
GetGroups() | Get group names and IDs for all groups in the organization |
GetTags() | Get tag names, IDs, and descriptions for tags in the organization |
Test Data
The GetTests() function is the primary way to retrieve performance test data. Use the filtering parameters to efficiently query only the data you need.
Key Parameters
| Parameter | Description |
|---|---|
from_ | Start time as Unix timestamp. Best for bulk historical exports |
to_ | End time as Unix timestamp. Defaults to now if omitted |
sync | When True, returns updated and newly created tests based on sync time. Best for incremental database sync |
includeInactive | Default False. Set True to include inactive tests |
athleteId | Filter by a specific athlete ID |
typeId | Filter by test type ID |
teamId | Filter by team ID(s), max 10 |
groupId | Filter by group ID(s), max 10 |
athleteId, typeId, teamId, or groupId together. Any of these can be used with from_, to_, sync, and includeInactive.
GetTestsAth, GetTestsType, GetTestsTeam, and GetTestsGroup have been deprecated in favor of GetTests() with filter parameters. Use GetTests() for all new code.
Example Usage
Full workflow examples demonstrating common hdforce patterns.
Log Configuration
Run at the beginning of your script or session to set desired logging settings.
Authentication
Environment Variable Method
First use in a new environment, storing the refresh token and region.
File Method
Using a .env file for variable storage. Create the file first, then authenticate.
Create Useful Variables
GetTests with Various Filters
Filter by Athlete
GetForceTime
Integrating with Web Applications
hdforce works seamlessly with popular Python web frameworks. Below are complete integration examples for Streamlit, FastAPI, and Dash.
Streamlit
Build interactive dashboards quickly with Streamlit. Use st.secrets or environment variables for secure token storage.
HD_REFRESH_TOKEN in the app settings under Secrets using TOML format: HD_REFRESH_TOKEN = "your_token_here". For local development, create a .streamlit/secrets.toml file.
FastAPI
Serve Hawkin data as REST endpoints. Authenticate on startup and let FastAPI handle requests.
HD_REFRESH_TOKEN environment variable on your server or pass it via a .env file. For Docker deployments, use docker run -e HD_REFRESH_TOKEN=your_token.
Dash
Build data-driven dashboards with Plotly Dash. Authenticate once at module level and use callbacks for interactivity.
HD_REFRESH_TOKEN as an environment variable on your hosting platform. For local development, use a .env file with the authMethod="file" option in AuthManager.
Function Reference
Complete documentation for all public hdforce functions — signatures, parameters, return values, and examples.
AuthManager(region, authMethod, refreshToken_name, refreshToken, env_file_name)
Manages authentication with the Hawkin Dynamics API. Exchanges a refresh token for an access token and stores the session credentials for use by all other hdforce functions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
region | str | "Americas" | API region: "Americas", "Europe", or "APAC" |
authMethod | str | "env" | Authentication method: "env" (system environment), "file" (.env file), or "manual" (direct token) |
refreshToken_name | str | "HD_REFRESH_TOKEN" | Name of the environment variable holding the refresh token |
refreshToken | str | None | The refresh token value. Required when authMethod="manual". When provided with "env" method, sets the environment variable |
env_file_name | str | None | Path to the .env file. Required when authMethod="file" |
Returns
Sets up the internal authentication state. All subsequent Get*() calls use the stored credentials automatically.
Example
LoggerConfig.Configuration(file, level, file_path, file_mode)
Configures the hdforce event logging system. Controls log output destination, verbosity level, file path, and file write mode.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
file | bool | False | If True, logs are written to a file instead of stdout |
level | str | "warning" | Minimum log level: "debug", "info", "warning", "error", "critical" |
file_path | str | "hdforce.log" | Path for the log file |
file_mode | str | "a" | "a" to append, "w" to overwrite each session |
Example
GetTests(from_, to_, sync, athleteId, typeId, teamId, groupId, includeInactive)
Retrieves test data from the Hawkin Dynamics API. The primary function for querying performance data. Replaces all previous GetTests* variations. Supports filtering by athlete, team, group, test type, and date range.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
from_ | int | None | Start time as Unix timestamp |
to_ | int | None | End time as Unix timestamp. Defaults to now |
sync | bool | False | If True, returns updated and newly created tests based on sync time |
athleteId | str | None | Filter by specific athlete ID |
typeId | str | None | Filter by test type ID |
teamId | str / list | None | Filter by team ID(s). Max 10 |
groupId | str / list | None | Filter by group ID(s). Max 10 |
includeInactive | bool | False | Include inactive tests in results |
Returns
A pandas DataFrame containing test trials and their metrics. Each row is a single test trial. The DataFrame includes attrs with metadata: Count, Last Sync, and Last Test Time.
Examples
GetForceTime(testId)
Retrieves the raw force-time data for a specific test trial. Returns high-frequency data sampled at 1000 Hz including left, right, and combined force, velocity, displacement, and power.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
testId | str | — | The unique identifier for the test trial |
Returns
A pandas DataFrame with columns for time, left force, right force, combined force, velocity, displacement, and power at each millisecond interval.
Example
GetTypes()
Get the test type names and IDs for all test types in the Hawkin Dynamics system.
Returns
A pandas DataFrame containing the test types with their canonical IDs and names.
Example
GetMetrics()
Get all metrics for each test type. Returns the canonical test type ID, test type name, metric ID, metric label, unit of measure, and description.
Returns
A pandas DataFrame with columns: canonicalTestTypeID, testTypeName, id, label, units, description.
Example
GetAthletes(includeInactive)
Get all athletes for an account. Inactive athletes are only included when includeInactive is set to True.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
includeInactive | bool | False | Include inactive athletes in the results |
Returns
A pandas DataFrame with columns: id, name, active, teams, groups, and any external properties.
Example
GetTeams()
Get team names and IDs for all teams in the organization.
Returns
A pandas DataFrame with columns: id, name.
Example
GetGroups()
Get group names and IDs for all groups in the organization.
Returns
A pandas DataFrame with columns: id, name.
Example
GetTags()
Get tag names, IDs, and descriptions for all tags created by users in your organization.
Returns
A pandas DataFrame with columns: id, name, description.
Example
CreateAthletes(athletes)
Create new athletes for an account. Accepts a list of NewAthlete objects. Bulk create up to 500 athletes at a time.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
athletes | list[NewAthlete] | — | A list of NewAthlete objects. Each requires a name (str). Optional: active (bool), teams (list), groups (list), image (str), and any external properties |
Returns
Prints confirmation with the count of created athletes. If any fail, returns details about the failures.
Example
UpdateAthletes(athletes)
Update existing athletes. Accepts a list of Athlete objects. Bulk update up to 500 athletes at a time.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
athletes | list[Athlete] | — | A list of Athlete objects. Each requires an id (str). Optional: name, active, teams, groups, image, and external properties |
external properties, any custom properties not included in the request will be removed from the athlete. Always include all external properties you want to keep.
Example
GetTests() with the appropriate filter parameters instead. These functions will be fully removed in a future release.
GetTestsAth(athleteId, from_, to_, sync, includeInactive)
Deprecated
Get tests for a specific athlete. Deprecated — use GetTests(athleteId=...) instead.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
athleteId | str | — | The athlete's unique ID |
from_ | int | None | Start time as Unix timestamp |
to_ | int | None | End time as Unix timestamp |
sync | bool | False | Use sync time instead of test time |
includeInactive | bool | False | Include inactive tests |
GetTestsAth(athleteId="abc") with GetTests(athleteId="abc"). The same applies to GetTestsType, GetTestsTeam, and GetTestsGroup — use GetTests() with the corresponding parameter.
Changelog
Release notes and version history for hdforce.
Athlete management and unified GetTests
- Added
CreateAthletes()andUpdateAthletes()functions for athlete management - Expanded
GetTests()to accept all filter parameters:athleteId,typeId,teamId,groupId - Breaking: Deprecated
GetTestsAth,GetTestsType,GetTestsTeam,GetTestsGroupin favor of unifiedGetTests()
Initial production release
- Full logging system with configurable output and levels
- Complete authentication management with environment, file, and manual methods
- Core data retrieval functions:
GetTests,GetAthletes,GetTeams,GetGroups,GetTags GetForceTimefor raw force-time waveform dataGetTypesandGetMetricsfor system metadata
Release candidate — logging and bug fixes
- Improved logging output formatting and consistency
- Fixed authentication token refresh edge cases
- Bug fixes for data frame column type handling
Initial build
- First beta release of hdforce
- Basic API authentication and data retrieval
- Pandas DataFrame output for all endpoints