Skip to content

Commit 48a57e9

Browse files
author
aman
committed
Add first experiments
1 parent e4c1adb commit 48a57e9

7 files changed

Lines changed: 126 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ Thumbs.db
4444
.ruff_cache/
4545
openapi.json
4646
openapi.codegen.json
47+
48+
.env

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Python SDK for the BodyLoop API for seamless ecosystem integration
44

55
The URL of the source repository <https://github.com/bodyloop/bodyloop-sdk-python> has suffix `python` to enable adding SDKs for other lanuages such as JavaScript/TypeScript, C/C++, Rust, etc.
66

7-
The distribution name (install) of the Python Package name is `bodyloop-sdk` and is available in the global Package Index PyPi at <https://pypi.org/project/bodyloop-sdk>. It omits the suffix since PyPi already tells us that we are in the Python ecosystem.
7+
The distribution name (install) of the Python Package name is `bodyloop-sdk` and is available in the global Package Index PyPi at <https://pypi.org/project/bodyloop-sdk>. It omits the suffix since PyPi already tells us that we are in the Python ecosystem.
88

99
Examples how to get the package are:
1010

@@ -58,6 +58,17 @@ The API generator <https://pypi.org/project/openapi-python-client/> is used.
5858
./generate_api_client.sh <ip_or_hostname_of_my_bodyloop_instance>
5959
```
6060

61+
Use the experiments to get your feet wet:
62+
63+
```bash
64+
touch .env
65+
echo "BODYLOOP_BASE_URL='https://bodyloop-control-pc'" >> .env
66+
echo "BODYLOOP_API_TOKEN='your_api_token_here'" >> .env
67+
68+
uv run experiments/a_create_client.py
69+
uv run experiments/b_load_probands.py
70+
```
71+
6172
## License
6273

6374
See [LICENSE](LICENSE)

experiments/a_create_client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
from pathlib import Path
6+
from dotenv import load_dotenv
7+
8+
# Load environment variables from .env file
9+
load_dotenv()
10+
11+
# Add the src directory (src-layout project) so `bodyloop_sdk` can be imported
12+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
13+
14+
from bodyloop_sdk.client import AuthenticatedClient
15+
16+
base_url = os.getenv("BODYLOOP_BASE_URL")
17+
api_token = os.getenv("BODYLOOP_API_TOKEN")
18+
19+
# Create a client with SSL verification disabled for local IP
20+
# Note: In production, you should use proper SSL certificates
21+
client = AuthenticatedClient(
22+
base_url=base_url,
23+
verify_ssl=False,
24+
token=api_token,
25+
timeout=10.0
26+
)
27+
28+
print(f"Client configured for: {base_url}")

experiments/b_load_probands.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
from pathlib import Path
6+
from dotenv import load_dotenv
7+
8+
# Load environment variables from .env file
9+
load_dotenv()
10+
11+
# Add the src directory (src-layout project) so `bodyloop_sdk` can be imported
12+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
13+
14+
from bodyloop_sdk.client import AuthenticatedClient
15+
16+
base_url = os.getenv("BODYLOOP_BASE_URL")
17+
api_token = os.getenv("BODYLOOP_API_TOKEN")
18+
19+
# (a) Create a client with SSL verification disabled for local IP)
20+
client = AuthenticatedClient(
21+
base_url=base_url,
22+
verify_ssl=False,
23+
token=api_token,
24+
timeout=10.0
25+
)
26+
27+
print(f"Client configured for: {base_url}")
28+
29+
30+
# (b) Load probands
31+
from functools import partial
32+
from bodyloop_sdk.client.api.probands import get_probands_api_v2_probands_get
33+
34+
get_probands = partial(get_probands_api_v2_probands_get.sync, client=client)
35+
36+
probands = get_probands() or []
37+
print(f"Total probands: {len(probands)}\n")
38+
39+
# Print first and last proband for sanity check
40+
if probands:
41+
print("First proband:")
42+
print(probands[0])
43+
print("\nLast proband:")
44+
print(probands[-1])
45+
46+
import json
47+
if probands:
48+
print("First proband:")
49+
print(json.dumps(probands[0].to_dict(), indent=2))
50+
print("\nLast proband:")
51+
print(json.dumps(probands[-1].to_dict(), indent=2))

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = { file = "LICENSE" }
77
requires-python = ">=3.11"
88
dependencies = [
99
"attrs>=25.4.0",
10+
"dotenv>=0.9.9",
1011
"httpx>=0.28.1",
1112
"python-dateutil>=2.9.0.post0",
1213
]

src/bodyloop_sdk/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
try:
66
# Python 3.8+
7-
from importlib.metadata import version as _pkg_version
7+
from importlib.metadata import PackageNotFoundError, version as _pkg_version
88
except ImportError: # pragma: no cover (for very old Pythons)
9-
from importlib_metadata import version as _pkg_version # type: ignore
9+
from importlib_metadata import ( # type: ignore
10+
PackageNotFoundError,
11+
version as _pkg_version,
12+
)
1013

1114

1215
def _read_version() -> str:
1316
# This must match the distribution name in pyproject.toml ([project].name)
14-
return _pkg_version("bodyloop-sdk")
17+
try:
18+
return _pkg_version("bodyloop-sdk")
19+
except PackageNotFoundError:
20+
# Fallback for running directly from source without an installed package.
21+
return "0.0.0.0"
1522

1623

1724
__version__ = _read_version()

uv.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)