Skip to main content

Python SDK for the HyperStudy experiment platform API

Project description

hyperstudy

Python SDK for the HyperStudy experiment platform API. Designed for researchers working in Jupyter, marimo, or Python scripts.

Installation

pip install hyperstudy

For polars support:

pip install hyperstudy[polars]

Quick Start

import hyperstudy

hs = hyperstudy.HyperStudy(api_key="hst_live_...")
# Or set the HYPERSTUDY_API_KEY environment variable

# Fetch events as a pandas DataFrame
events = hs.get_events("your_experiment_id")

# Room-scoped data
events = hs.get_events("room_id", scope="room")

# Participant-scoped data
events = hs.get_events("participant_id", scope="participant", room_id="room_id")

Data Types

All data retrieval methods follow the same pattern:

events        = hs.get_events("exp_id")
recordings    = hs.get_recordings("exp_id")
chat          = hs.get_chat("exp_id")
videochat     = hs.get_videochat("exp_id")
sync          = hs.get_sync("exp_id")
ratings       = hs.get_ratings("exp_id", kind="continuous")
components    = hs.get_components("exp_id")
participants  = hs.get_participants("exp_id")
rooms         = hs.get_rooms("exp_id")

# Convenience methods for common event categories
questionnaire = hs.get_questionnaire("exp_id")
instructions  = hs.get_instructions("exp_id")
consent       = hs.get_consent("exp_id")

Output Formats

df_pandas = hs.get_events("exp_id")                      # pandas (default)
df_polars = hs.get_events("exp_id", output="polars")     # polars
raw       = hs.get_events("exp_id", output="dict")       # list[dict]

Filtering

events = hs.get_events(
    "exp_id",
    start_time="2024-01-01T10:00:00Z",
    end_time="2024-01-01T12:00:00Z",
    category="component",
    sort="onset",
    limit=100,
)

Auto-Pagination

When limit is not set, all pages are fetched automatically with a progress bar:

all_events = hs.get_events("exp_id")  # fetches all pages

Experiment Management

# List experiments
experiments = hs.list_experiments()

# Get details (with rich display in notebooks)
exp = hs.get_experiment("exp_id")

# Quick create / update / delete (kwargs form, backwards-compatible)
new_exp = hs.create_experiment(name="My Study", description="...")
hs.update_experiment("exp_id", name="Updated Name")
hs.delete_experiment("exp_id")

Building experiments programmatically (0.3.0+)

For full experiment definitions — states, components, roles — use the typed Experiment builder. Snake_case Python fields convert to the camelCase wire format automatically.

from hyperstudy import Experiment, State, Role, show_text, vas_rating

exp = Experiment(
    name="Two-person study",
    required_participants=2,
    states=[
        State(id="intro", focus_component=show_text("Welcome")),
        State(
            id="rate",
            focus_component=vas_rating("Rate the clip", output_variable="rating"),
        ),
    ],
    roles={"speaker": Role(name="Speaker", participant_count=1)},
)

# Dry-run validation against the backend.
print(hs.validate_experiment(exp))  # → {"valid": True, ...}

# Create.
info = hs.create_experiment(experiment=exp)

Component factories cover show_text, show_image, show_video, vas_rating, text_input, multiple_choice, waiting, likert_scale, ranking. For other component types, construct directly: FocusComponent(type=ComponentType.X, config={...}). See the Experiment Authoring guide for the full reference.

Deployments

# List deployments
deployments = hs.list_deployments()
deployments = hs.list_deployments(experiment_id="exp_id", status="active")

# Get deployment details
dep = hs.get_deployment("deployment_id")

# List sessions/rooms for a deployment
sessions = hs.get_deployment_sessions("deployment_id")

All Data for a Participant

data = hs.get_all_data("participant_id", room_id="room_id")
# Returns dict with keys: events, recordings, chat, videochat, sync,
# ratings_continuous, ratings_sparse, components, questionnaire,
# instructions, consent

API Key

Generate an API key from the HyperStudy dashboard under Settings. Keys follow the format hst_{environment}_{key} and are passed via the X-API-Key header.

Documentation

Full documentation: docs.hyperstudy.io/developers/python-sdk

Development

git clone https://github.com/hyperstudyio/hyperstudy-pythonsdk.git
cd hyperstudy-pythonsdk
pip install -e ".[dev,polars]"
pytest --cov=hyperstudy
ruff check src/

License

MIT

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

hyperstudy-0.3.1.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyperstudy-0.3.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file hyperstudy-0.3.1.tar.gz.

File metadata

  • Download URL: hyperstudy-0.3.1.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hyperstudy-0.3.1.tar.gz
Algorithm Hash digest
SHA256 dc0300caf1a9b73177b0d6a98ed0337ffc79e8f17fe4c9ad6952a11c7bb03bea
MD5 bf8b2e538334123bd6f506e9d19fe763
BLAKE2b-256 fc86d09f61d5405f2e8153a9ce22818a04d06703e8eb730e2aee8aa930af10a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperstudy-0.3.1.tar.gz:

Publisher: publish.yml on hyperstudyio/hyperstudy-pythonsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperstudy-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: hyperstudy-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hyperstudy-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1e240d604009ccf3cba99bfd9787288cf9a429f3355bdff6dc1a8198d42fd88
MD5 330179fb1fe25cf3231c2653c7ff4754
BLAKE2b-256 897b2600588e0b9c1ae83ba16d9294ed51304c63f3bac24a6c22fbadb6af0f1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperstudy-0.3.1-py3-none-any.whl:

Publisher: publish.yml on hyperstudyio/hyperstudy-pythonsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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