hyperstudy 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. hyperstudy-0.1.0/.github/workflows/publish.yml +27 -0
  2. hyperstudy-0.1.0/.github/workflows/sync-release-notes.yml +67 -0
  3. hyperstudy-0.1.0/.github/workflows/test.yml +29 -0
  4. hyperstudy-0.1.0/.gitignore +15 -0
  5. hyperstudy-0.1.0/CHANGELOG.md +17 -0
  6. hyperstudy-0.1.0/LICENSE +21 -0
  7. hyperstudy-0.1.0/PKG-INFO +155 -0
  8. hyperstudy-0.1.0/README.md +122 -0
  9. hyperstudy-0.1.0/pyproject.toml +58 -0
  10. hyperstudy-0.1.0/src/hyperstudy/__init__.py +38 -0
  11. hyperstudy-0.1.0/src/hyperstudy/_dataframe.py +68 -0
  12. hyperstudy-0.1.0/src/hyperstudy/_display.py +64 -0
  13. hyperstudy-0.1.0/src/hyperstudy/_http.py +128 -0
  14. hyperstudy-0.1.0/src/hyperstudy/_pagination.py +61 -0
  15. hyperstudy-0.1.0/src/hyperstudy/_types.py +30 -0
  16. hyperstudy-0.1.0/src/hyperstudy/client.py +368 -0
  17. hyperstudy-0.1.0/src/hyperstudy/exceptions.py +58 -0
  18. hyperstudy-0.1.0/src/hyperstudy/experiments.py +125 -0
  19. hyperstudy-0.1.0/tests/__init__.py +0 -0
  20. hyperstudy-0.1.0/tests/conftest.py +74 -0
  21. hyperstudy-0.1.0/tests/fixtures/error_401.json +7 -0
  22. hyperstudy-0.1.0/tests/fixtures/error_403.json +11 -0
  23. hyperstudy-0.1.0/tests/fixtures/events_response.json +68 -0
  24. hyperstudy-0.1.0/tests/fixtures/experiment_single_response.json +24 -0
  25. hyperstudy-0.1.0/tests/fixtures/experiments_list_response.json +38 -0
  26. hyperstudy-0.1.0/tests/fixtures/paginated_page1.json +21 -0
  27. hyperstudy-0.1.0/tests/fixtures/paginated_page2.json +19 -0
  28. hyperstudy-0.1.0/tests/test_client.py +265 -0
  29. hyperstudy-0.1.0/tests/test_dataframe.py +78 -0
  30. hyperstudy-0.1.0/tests/test_experiments.py +197 -0
  31. hyperstudy-0.1.0/tests/test_pagination.py +71 -0
@@ -0,0 +1,27 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ id-token: write
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.12"
19
+
20
+ - name: Install build tools
21
+ run: pip install build
22
+
23
+ - name: Build package
24
+ run: python -m build
25
+
26
+ - name: Publish to PyPI
27
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,67 @@
1
+ name: Sync Release Notes to Docs
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ sync:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - name: Get release info
13
+ id: release
14
+ env:
15
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16
+ run: |
17
+ TAG="${{ github.event.release.tag_name }}"
18
+ echo "tag=$TAG" >> $GITHUB_OUTPUT
19
+
20
+ BODY=$(gh release view "$TAG" --repo ${{ github.repository }} --json body -q '.body')
21
+ echo "body<<EOF" >> $GITHUB_OUTPUT
22
+ echo "$BODY" >> $GITHUB_OUTPUT
23
+ echo "EOF" >> $GITHUB_OUTPUT
24
+
25
+ - name: Checkout hyperstudy-docs
26
+ uses: actions/checkout@v4
27
+ with:
28
+ repository: ljchang/hyperstudy-docs
29
+ token: ${{ secrets.DOCS_REPO_TOKEN }}
30
+ path: docs-repo
31
+
32
+ - name: Create release notes
33
+ run: |
34
+ cd docs-repo
35
+ TAG="${{ steps.release.outputs.tag }}"
36
+ DIR="docs/release-notes/python-sdk"
37
+ FILE="$DIR/${TAG}.md"
38
+
39
+ mkdir -p "$DIR"
40
+
41
+ cat > "$FILE" << EOF
42
+ ---
43
+ title: Python SDK ${TAG}
44
+ ---
45
+
46
+ # Python SDK ${TAG}
47
+
48
+ Released: $(date -u +"%Y-%m-%d")
49
+
50
+ ${{ steps.release.outputs.body }}
51
+ EOF
52
+
53
+ # Remove leading whitespace from heredoc
54
+ sed -i 's/^ //' "$FILE"
55
+
56
+ - name: Create PR to hyperstudy-docs
57
+ uses: peter-evans/create-pull-request@v6
58
+ with:
59
+ path: docs-repo
60
+ token: ${{ secrets.DOCS_REPO_TOKEN }}
61
+ title: "docs: Python SDK ${{ steps.release.outputs.tag }} release notes"
62
+ branch: "python-sdk-release-${{ steps.release.outputs.tag }}"
63
+ commit-message: "Add Python SDK ${{ steps.release.outputs.tag }} release notes"
64
+ body: |
65
+ Auto-generated release notes for Python SDK ${{ steps.release.outputs.tag }}.
66
+
67
+ Source: ${{ github.event.release.html_url }}
@@ -0,0 +1,29 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main, dev]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+
22
+ - name: Install dependencies
23
+ run: pip install -e ".[dev,polars]"
24
+
25
+ - name: Lint
26
+ run: ruff check src/
27
+
28
+ - name: Run tests
29
+ run: pytest --cov=hyperstudy --cov-report=term-missing -v
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ *.egg
8
+ .pytest_cache/
9
+ .coverage
10
+ htmlcov/
11
+ .ruff_cache/
12
+ .venv/
13
+ venv/
14
+ *.whl
15
+ .DS_Store
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## v0.1.0
4
+
5
+ Initial release.
6
+
7
+ ### Features
8
+
9
+ - `HyperStudy` client with API key authentication (constructor arg or `HYPERSTUDY_API_KEY` env var)
10
+ - Data retrieval methods: `get_events`, `get_recordings`, `get_chat`, `get_videochat`, `get_sync`, `get_ratings`, `get_components`, `get_participants`, `get_rooms`
11
+ - `get_all_data` convenience method for fetching all data types for a single participant
12
+ - Auto-pagination with `tqdm` progress bars (notebook and terminal)
13
+ - Output format options: `"pandas"` (default), `"polars"`, `"dict"`
14
+ - Experiment management: `list_experiments`, `get_experiment`, `get_experiment_config`, `create_experiment`, `update_experiment`, `delete_experiment`
15
+ - Rich notebook display (`_repr_html_`) for experiment objects
16
+ - Typed exceptions: `AuthenticationError`, `ForbiddenError`, `NotFoundError`, `ValidationError`, `ServerError`
17
+ - `health()` method for connection testing
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Luke Chang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyperstudy
3
+ Version: 0.1.0
4
+ Summary: Python SDK for the HyperStudy experiment platform API
5
+ Project-URL: Homepage, https://hyperstudy.io
6
+ Project-URL: Documentation, https://docs.hyperstudy.io/developers/python-sdk
7
+ Project-URL: Repository, https://github.com/ljchang/hyperstudy-pythonsdk
8
+ Project-URL: Issues, https://github.com/ljchang/hyperstudy-pythonsdk/issues
9
+ Author-email: Luke Chang <luke.j.chang@dartmouth.edu>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Requires-Python: >=3.9
22
+ Requires-Dist: pandas>=1.5.0
23
+ Requires-Dist: requests>=2.28.0
24
+ Requires-Dist: tqdm>=4.60.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest-cov; extra == 'dev'
27
+ Requires-Dist: pytest>=7.0; extra == 'dev'
28
+ Requires-Dist: responses>=0.23.0; extra == 'dev'
29
+ Requires-Dist: ruff; extra == 'dev'
30
+ Provides-Extra: polars
31
+ Requires-Dist: polars>=0.20.0; extra == 'polars'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # hyperstudy
35
+
36
+ Python SDK for the [HyperStudy](https://hyperstudy.io) experiment platform API. Designed for researchers working in Jupyter, marimo, or Python scripts.
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install hyperstudy
42
+ ```
43
+
44
+ For polars support:
45
+
46
+ ```bash
47
+ pip install hyperstudy[polars]
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ```python
53
+ import hyperstudy
54
+
55
+ hs = hyperstudy.HyperStudy(api_key="hst_live_...")
56
+ # Or set the HYPERSTUDY_API_KEY environment variable
57
+
58
+ # Fetch events as a pandas DataFrame
59
+ events = hs.get_events("your_experiment_id")
60
+
61
+ # Room-scoped data
62
+ events = hs.get_events("room_id", scope="room")
63
+
64
+ # Participant-scoped data
65
+ events = hs.get_events("participant_id", scope="participant", room_id="room_id")
66
+ ```
67
+
68
+ ## Data Types
69
+
70
+ All data retrieval methods follow the same pattern:
71
+
72
+ ```python
73
+ events = hs.get_events("exp_id")
74
+ recordings = hs.get_recordings("exp_id")
75
+ chat = hs.get_chat("exp_id")
76
+ videochat = hs.get_videochat("exp_id")
77
+ sync = hs.get_sync("exp_id")
78
+ ratings = hs.get_ratings("exp_id", kind="continuous")
79
+ components = hs.get_components("exp_id")
80
+ participants = hs.get_participants("exp_id")
81
+ rooms = hs.get_rooms("exp_id")
82
+ ```
83
+
84
+ ### Output Formats
85
+
86
+ ```python
87
+ df_pandas = hs.get_events("exp_id") # pandas (default)
88
+ df_polars = hs.get_events("exp_id", output="polars") # polars
89
+ raw = hs.get_events("exp_id", output="dict") # list[dict]
90
+ ```
91
+
92
+ ### Filtering
93
+
94
+ ```python
95
+ events = hs.get_events(
96
+ "exp_id",
97
+ start_time="2024-01-01T10:00:00Z",
98
+ end_time="2024-01-01T12:00:00Z",
99
+ category="component",
100
+ sort="onset",
101
+ limit=100,
102
+ )
103
+ ```
104
+
105
+ ### Auto-Pagination
106
+
107
+ When `limit` is not set, all pages are fetched automatically with a progress bar:
108
+
109
+ ```python
110
+ all_events = hs.get_events("exp_id") # fetches all pages
111
+ ```
112
+
113
+ ## Experiment Management
114
+
115
+ ```python
116
+ # List experiments
117
+ experiments = hs.list_experiments()
118
+
119
+ # Get details (with rich display in notebooks)
120
+ exp = hs.get_experiment("exp_id")
121
+
122
+ # Create / update / delete
123
+ new_exp = hs.create_experiment(name="My Study", description="...")
124
+ hs.update_experiment("exp_id", name="Updated Name")
125
+ hs.delete_experiment("exp_id")
126
+ ```
127
+
128
+ ## All Data for a Participant
129
+
130
+ ```python
131
+ data = hs.get_all_data("participant_id", room_id="room_id")
132
+ # Returns: {"events": DataFrame, "recordings": DataFrame, "chat": DataFrame, ...}
133
+ ```
134
+
135
+ ## API Key
136
+
137
+ 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.
138
+
139
+ ## Documentation
140
+
141
+ Full documentation: [docs.hyperstudy.io/developers/python-sdk](https://docs.hyperstudy.io/developers/python-sdk)
142
+
143
+ ## Development
144
+
145
+ ```bash
146
+ git clone https://github.com/ljchang/hyperstudy-pythonsdk.git
147
+ cd hyperstudy-pythonsdk
148
+ pip install -e ".[dev,polars]"
149
+ pytest --cov=hyperstudy
150
+ ruff check src/
151
+ ```
152
+
153
+ ## License
154
+
155
+ MIT
@@ -0,0 +1,122 @@
1
+ # hyperstudy
2
+
3
+ Python SDK for the [HyperStudy](https://hyperstudy.io) experiment platform API. Designed for researchers working in Jupyter, marimo, or Python scripts.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install hyperstudy
9
+ ```
10
+
11
+ For polars support:
12
+
13
+ ```bash
14
+ pip install hyperstudy[polars]
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```python
20
+ import hyperstudy
21
+
22
+ hs = hyperstudy.HyperStudy(api_key="hst_live_...")
23
+ # Or set the HYPERSTUDY_API_KEY environment variable
24
+
25
+ # Fetch events as a pandas DataFrame
26
+ events = hs.get_events("your_experiment_id")
27
+
28
+ # Room-scoped data
29
+ events = hs.get_events("room_id", scope="room")
30
+
31
+ # Participant-scoped data
32
+ events = hs.get_events("participant_id", scope="participant", room_id="room_id")
33
+ ```
34
+
35
+ ## Data Types
36
+
37
+ All data retrieval methods follow the same pattern:
38
+
39
+ ```python
40
+ events = hs.get_events("exp_id")
41
+ recordings = hs.get_recordings("exp_id")
42
+ chat = hs.get_chat("exp_id")
43
+ videochat = hs.get_videochat("exp_id")
44
+ sync = hs.get_sync("exp_id")
45
+ ratings = hs.get_ratings("exp_id", kind="continuous")
46
+ components = hs.get_components("exp_id")
47
+ participants = hs.get_participants("exp_id")
48
+ rooms = hs.get_rooms("exp_id")
49
+ ```
50
+
51
+ ### Output Formats
52
+
53
+ ```python
54
+ df_pandas = hs.get_events("exp_id") # pandas (default)
55
+ df_polars = hs.get_events("exp_id", output="polars") # polars
56
+ raw = hs.get_events("exp_id", output="dict") # list[dict]
57
+ ```
58
+
59
+ ### Filtering
60
+
61
+ ```python
62
+ events = hs.get_events(
63
+ "exp_id",
64
+ start_time="2024-01-01T10:00:00Z",
65
+ end_time="2024-01-01T12:00:00Z",
66
+ category="component",
67
+ sort="onset",
68
+ limit=100,
69
+ )
70
+ ```
71
+
72
+ ### Auto-Pagination
73
+
74
+ When `limit` is not set, all pages are fetched automatically with a progress bar:
75
+
76
+ ```python
77
+ all_events = hs.get_events("exp_id") # fetches all pages
78
+ ```
79
+
80
+ ## Experiment Management
81
+
82
+ ```python
83
+ # List experiments
84
+ experiments = hs.list_experiments()
85
+
86
+ # Get details (with rich display in notebooks)
87
+ exp = hs.get_experiment("exp_id")
88
+
89
+ # Create / update / delete
90
+ new_exp = hs.create_experiment(name="My Study", description="...")
91
+ hs.update_experiment("exp_id", name="Updated Name")
92
+ hs.delete_experiment("exp_id")
93
+ ```
94
+
95
+ ## All Data for a Participant
96
+
97
+ ```python
98
+ data = hs.get_all_data("participant_id", room_id="room_id")
99
+ # Returns: {"events": DataFrame, "recordings": DataFrame, "chat": DataFrame, ...}
100
+ ```
101
+
102
+ ## API Key
103
+
104
+ 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.
105
+
106
+ ## Documentation
107
+
108
+ Full documentation: [docs.hyperstudy.io/developers/python-sdk](https://docs.hyperstudy.io/developers/python-sdk)
109
+
110
+ ## Development
111
+
112
+ ```bash
113
+ git clone https://github.com/ljchang/hyperstudy-pythonsdk.git
114
+ cd hyperstudy-pythonsdk
115
+ pip install -e ".[dev,polars]"
116
+ pytest --cov=hyperstudy
117
+ ruff check src/
118
+ ```
119
+
120
+ ## License
121
+
122
+ MIT
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "hyperstudy"
7
+ version = "0.1.0"
8
+ description = "Python SDK for the HyperStudy experiment platform API"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.9"
12
+ authors = [
13
+ { name = "Luke Chang", email = "luke.j.chang@dartmouth.edu" },
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Science/Research",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Topic :: Scientific/Engineering",
25
+ ]
26
+ dependencies = [
27
+ "requests>=2.28.0",
28
+ "pandas>=1.5.0",
29
+ "tqdm>=4.60.0",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ polars = ["polars>=0.20.0"]
34
+ dev = [
35
+ "pytest>=7.0",
36
+ "pytest-cov",
37
+ "responses>=0.23.0",
38
+ "ruff",
39
+ ]
40
+
41
+ [project.urls]
42
+ Homepage = "https://hyperstudy.io"
43
+ Documentation = "https://docs.hyperstudy.io/developers/python-sdk"
44
+ Repository = "https://github.com/ljchang/hyperstudy-pythonsdk"
45
+ Issues = "https://github.com/ljchang/hyperstudy-pythonsdk/issues"
46
+
47
+ [tool.hatch.build.targets.wheel]
48
+ packages = ["src/hyperstudy"]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+
53
+ [tool.ruff]
54
+ target-version = "py39"
55
+ line-length = 100
56
+
57
+ [tool.ruff.lint]
58
+ select = ["E", "F", "I", "W"]
@@ -0,0 +1,38 @@
1
+ """HyperStudy Python SDK — access experiment data from notebooks and scripts.
2
+
3
+ Usage::
4
+
5
+ import hyperstudy
6
+
7
+ hs = hyperstudy.HyperStudy(api_key="hst_live_...")
8
+ events = hs.get_events("experiment_id")
9
+ """
10
+
11
+ from ._types import DataType, RatingKind, Scope
12
+ from .client import HyperStudy
13
+ from .exceptions import (
14
+ AuthenticationError,
15
+ ForbiddenError,
16
+ HyperStudyError,
17
+ NotFoundError,
18
+ ServerError,
19
+ ValidationError,
20
+ )
21
+
22
+ __version__ = "0.1.0"
23
+
24
+ __all__ = [
25
+ "HyperStudy",
26
+ "__version__",
27
+ # Exceptions
28
+ "HyperStudyError",
29
+ "AuthenticationError",
30
+ "ForbiddenError",
31
+ "NotFoundError",
32
+ "ServerError",
33
+ "ValidationError",
34
+ # Enums
35
+ "Scope",
36
+ "DataType",
37
+ "RatingKind",
38
+ ]
@@ -0,0 +1,68 @@
1
+ """DataFrame conversion for API response data."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ import pandas as pd
8
+
9
+
10
+ def _post_process(df: pd.DataFrame) -> pd.DataFrame:
11
+ """Shared post-processing for pandas DataFrames.
12
+
13
+ * Parses timestamp columns to datetime.
14
+ * Computes ``onset_sec`` from ``onset`` (ms -> s).
15
+ """
16
+ if df.empty:
17
+ return df
18
+
19
+ # Parse common timestamp columns
20
+ for col in ("timestamp", "startTime", "endTime", "createdAt", "updatedAt"):
21
+ if col in df.columns:
22
+ df[col] = pd.to_datetime(df[col], errors="coerce")
23
+
24
+ # Compute onset in seconds
25
+ if "onset" in df.columns:
26
+ df["onset_sec"] = pd.to_numeric(df["onset"], errors="coerce") / 1000.0
27
+
28
+ return df
29
+
30
+
31
+ def to_pandas(data: list[dict[str, Any]]) -> pd.DataFrame:
32
+ """Convert API response data to a pandas DataFrame with post-processing."""
33
+ if not data:
34
+ return pd.DataFrame()
35
+ df = pd.DataFrame(data)
36
+ return _post_process(df)
37
+
38
+
39
+ def to_polars(data: list[dict[str, Any]]):
40
+ """Convert API response data to a polars DataFrame.
41
+
42
+ Raises ImportError with a helpful message if polars is not installed.
43
+ """
44
+ try:
45
+ import polars as pl
46
+ except ImportError:
47
+ raise ImportError(
48
+ "polars is not installed. Install it with: pip install hyperstudy[polars]"
49
+ ) from None
50
+
51
+ if not data:
52
+ return pl.DataFrame()
53
+
54
+ df = pl.DataFrame(data)
55
+
56
+ # Parse timestamps
57
+ for col in ("timestamp", "startTime", "endTime", "createdAt", "updatedAt"):
58
+ if col in df.columns:
59
+ try:
60
+ df = df.with_columns(pl.col(col).str.to_datetime(strict=False).alias(col))
61
+ except Exception:
62
+ pass # Column may already be datetime or have unexpected format
63
+
64
+ # Compute onset_sec
65
+ if "onset" in df.columns:
66
+ df = df.with_columns((pl.col("onset").cast(pl.Float64) / 1000.0).alias("onset_sec"))
67
+
68
+ return df
@@ -0,0 +1,64 @@
1
+ """Rich display helpers for Jupyter and marimo notebooks."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+
8
+ class ExperimentInfo:
9
+ """Wrapper around an experiment dict with ``_repr_html_`` for notebooks."""
10
+
11
+ def __init__(self, data: dict[str, Any]):
12
+ self._data = data
13
+
14
+ def __getitem__(self, key):
15
+ return self._data[key]
16
+
17
+ def __contains__(self, key):
18
+ return key in self._data
19
+
20
+ def get(self, key, default=None):
21
+ return self._data.get(key, default)
22
+
23
+ def keys(self):
24
+ return self._data.keys()
25
+
26
+ def values(self):
27
+ return self._data.values()
28
+
29
+ def items(self):
30
+ return self._data.items()
31
+
32
+ def to_dict(self) -> dict[str, Any]:
33
+ return dict(self._data)
34
+
35
+ def __repr__(self):
36
+ name = self._data.get("name", "Unknown")
37
+ eid = self._data.get("id", "?")
38
+ return f"Experiment({eid!r}, name={name!r})"
39
+
40
+ def _repr_html_(self) -> str:
41
+ d = self._data
42
+ rows = ""
43
+ display_fields = [
44
+ ("ID", "id"),
45
+ ("Name", "name"),
46
+ ("Description", "description"),
47
+ ("Owner", "ownerEmail"),
48
+ ("Rooms", "roomCount"),
49
+ ("Participants", "participantCount"),
50
+ ("Created", "createdAt"),
51
+ ("Updated", "updatedAt"),
52
+ ]
53
+ for label, key in display_fields:
54
+ val = d.get(key)
55
+ if val is not None:
56
+ rows += (
57
+ f"<tr><th style='text-align:left;padding:4px 12px 4px 0'>"
58
+ f"{label}</th><td style='padding:4px 0'>{val}</td></tr>"
59
+ )
60
+ return (
61
+ "<div style='font-family:system-ui,sans-serif;max-width:600px'>"
62
+ f"<h4 style='margin:0 0 8px'>Experiment: {d.get('name', '?')}</h4>"
63
+ f"<table style='border-collapse:collapse'>{rows}</table></div>"
64
+ )