lunapi
Python interface to the Luna C/C++ sleep-signal analysis engine.
lunapi exposes the full Luna command set to Python, enabling scripted and notebook-based workflows for polysomnographic (PSG) data — using the same analytical core as the Luna command-line tool and the Lunascope desktop application.
Statement of Need
Large-scale sleep research increasingly requires processing thousands of PSG recordings programmatically, while maintaining the ability to inspect individual records interactively. Existing Python EEG libraries are general-purpose frameworks that lack dedicated sleep-analysis primitives. lunapi provides direct Python access to Luna's domain-specific command set — covering spectral analysis, sleep staging, annotation handling, artifact detection, connectivity, and more — without requiring users to leave the Python/notebook environment or learn the Luna command-line interface.
Features
- Full Luna command set — run any Luna command (PSD, SPINDLES, SOAP, POPS, …) directly from Python and receive structured results as DataFrames
- Project-level workflows — load a sample list and execute commands across an entire cohort in a few lines
- Per-recording access — attach EDF and annotation files, extract raw signals and annotation events, insert or modify signals in memory
- Structured output — results returned as
pandasDataFrames keyed by command and stratum - SQLite result stores — write output to
.dbfiles that can be queried as virtual TSV-like tables - Sleep staging — SOAP and POPS automated staging models accessible directly from Python
- Visualization helpers — hypnogram, PSD, spectrogram, and topographic map plotting for notebooks
- NSRR Moonbeam — download and attach recordings directly from the National Sleep Research Resource
- GPA association modeling — linear association analysis on cohort-level result matrices
- Docker containers — pre-built images with Luna,
lunapi, and all dependencies
Installation
lunapi is distributed as a binary wheel via PyPI (no compiler required):
pip install lunapi
Supported platforms: macOS (Intel & Apple Silicon), Linux (x86_64), Windows 10/11 (x86_64), Python 3.9–3.14.
Using a virtual environment is recommended:
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install lunapi
Worked Example
Single-recording workflow
import lunapi as lp
# Create a project and attach a recording
p = lp.proj(verbose=False)
rec = p.inst("my_subject")
rec.attach_edf("/path/to/recording.edf")
rec.attach_annot("/path/to/recording.annot")
# List available channels
print(rec.chs())
# Run a Luna command and retrieve results as a DataFrame
rec.eval("PSD sig=EEG dB spectrum")
df = rec.table("PSD", "CH_F")
print(df.head())
Cohort workflow
import lunapi as lp
p = lp.proj(verbose=False)
p.sample_list("study.lst") # three-column file: ID, EDF path, annot path
# Run PSD across all recordings (returns dict of DataFrames)
results = p.proc("PSD sig=EEG dB spectrum")
df = results["PSD"]["CH_F"]
print(df.groupby("CH")["PSD"].mean())
Python destrat command
The package also installs destrat.py, a Python/SQLite reader for Luna
output databases. It accepts the common native destrat query options,
including row and column stratifiers and level restrictions:
destrat.py out.db
destrat.py out.db +PSD -r CH F -v PSD
destrat.py out.db +PSD -r F/11,15 CH -c B -v PSD
Multiple databases and glob patterns are accepted. Extracted tables are
written as tab-delimited output to standard output, so they can be redirected
or piped to another program. The same reader is available from Python as
lp.destrat(...).
Automated sleep staging
rec.eval("RUN-POPS sig=C3 ref=M2 path=~/dropbox/pops") # point to downloaded POPS models
stages = rec.table("RUN_POPS", "E") # per-epoch predictions
print(stages["PRED"].value_counts())
Full documentation, command reference, and interactive notebooks are at zzz.nyspi.org/luna/.
Testing
pip install -e ".[dev]"
pytest
This runs 59 tests covering the core workflow (load instance, run commands, retrieve tables, extract signals, annotation handling, sample-list workflow), visualization helpers, GPA utilities, and package smoke tests. No real EDF files are required — a synthetic in-memory recording is generated by the test fixtures.
Documentation
| Resource | URL |
|---|---|
| Luna ecosystem | https://zzz.nyspi.org/luna/ |
| lunapi notebooks | https://github.com/remnrem/luna-api/tree/main/notebooks |
| Lunascope desktop app | https://github.com/Lorcan7274/lunascope |
| NSRR | https://sleepdata.org |
Contributing
See CONTRIBUTING.md for guidelines on bug reports, feature requests, and pull requests.
Questions / Support
Open an issue on GitHub or write to luna.remnrem@gmail.com.
Metadata
Release files for lunapi 1.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 351.3 MB
Release files / lunapi-1.7.1-cp314-cp314-win_amd64.whl
| Download URL | lunapi-1.7.1-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 12.4 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9313d2aea64145f3e6db514b655ad33eda23d4e4251efadedcd9b979a2efc05f
|
|
BLAKE2b-256 checksum How to use checksums |
81b057ae81069cd122410dccbe0fa9f26f0c9135d1dd874ddfc7963e677a8368
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.17
|
Release files / lunapi-1.7.1-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | lunapi-1.7.1-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 14.5 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
28d833ae79e4fe2affd43b8b91fd810d2552ad84368009c87259e5b700cfab18
|
|
BLAKE2b-256 checksum How to use checksums |
f1184f2966d2f07115fd74576f056ff8913e4aa4304df51f926c06f95ae2fd10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / lunapi-1.7.1-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | lunapi-1.7.1-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 14.9 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
847bad7c766848219c2ce8c130ac07ffe992ec6b2e1fbea38861d77f5ed2af62
|
|
BLAKE2b-256 checksum How to use checksums |
9d3427b655d1dfcf803681554ff656513750ce3d29f1ba9691c39e75634e28b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / lunapi-1.7.1-cp314-cp314-macosx_10_15_x86_64.whl
| Download URL | lunapi-1.7.1-cp314-cp314-macosx_10_15_x86_64.whl |
|---|---|
| Size | 16.9 MB |
| Tags | CPython 3.14 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
648522ff279255fe437f39d876adacde91d2adb82ec2d8d9b77ebee94ab58f9f
|
|
BLAKE2b-256 checksum How to use checksums |
16b662a3e366aca4caa99adf5d16df3439cfca8c77639390d17fa576e2f62c87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / lunapi-1.7.1-cp313-cp313-win_amd64.whl
| Download URL | lunapi-1.7.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 12.2 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c58239cf11e4feed3f10b203a5d667dc87fc9e772f4192a6d3033f3fb3ff8d52
|
|
BLAKE2b-256 checksum How to use checksums |
2f58981a0228791763355965583faeddc92d332f35d8fd239912e0b715211225
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.17
|
Release files / lunapi-1.7.1-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | lunapi-1.7.1-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 14.5 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
188721a86d94a084562f609721715b78d85886acd8c5fab6ea7c091a69e1de02
|
|
BLAKE2b-256 checksum How to use checksums |
5f825d1048d7eb734ca03b3cc6b070f8dd414ed591adbaee7cffdaefa1c31764
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / lunapi-1.7.1-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | lunapi-1.7.1-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 14.9 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3b3536ba228754b5687e1fb470a54472954ff4a30253a156a7ca5e98536fe5e0
|
|
BLAKE2b-256 checksum How to use checksums |
04ed09b4f6a0b70b4d8850d720b4aafb46286b5ab93d8223a0a9c43fbca6d1f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / lunapi-1.7.1-cp313-cp313-macosx_10_15_x86_64.whl
| Download URL | lunapi-1.7.1-cp313-cp313-macosx_10_15_x86_64.whl |
|---|---|
| Size | 16.9 MB |
| Tags | CPython 3.13 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
d696a8af644adaea25d0ce8529faf3e45b2fc7050ec5f83f3d5348784beaa373
|
|
BLAKE2b-256 checksum How to use checksums |
26295780eaf1411e5d3cd9befa4edf4569e0ac0aef8622f323582833c8667e79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / lunapi-1.7.1-cp312-cp312-win_amd64.whl
| Download URL | lunapi-1.7.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 12.2 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
28e17bee156b48b465715dcc18162e886e2f102eb92fd43db1bc0bcfa3e18df7
|
|
BLAKE2b-256 checksum How to use checksums |
30ac07f8e1d6ceba7defeeb25d1ff382188a5a73a74e25e36beff6e8240a233d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.17
|
Release files / lunapi-1.7.1-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | lunapi-1.7.1-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 14.5 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
15944ac9c329ee0d3a344b8fe6a803e31e9dac309242baf1c84b64d274fa9661
|
|
BLAKE2b-256 checksum How to use checksums |
309d72b7b0fc0e641ebe98875d948e467dbab5cceaa5bc4757cf26d9ca16892d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / lunapi-1.7.1-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | lunapi-1.7.1-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 14.9 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0a4f1fdd85d0c6c5bb3b270ecd2f69461db729c07afb124571e871b926ecb264
|
|
BLAKE2b-256 checksum How to use checksums |
9222d0b01022b1c32de12141e09c62c1ea49d1777fbb99022e960dc624c45514
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / lunapi-1.7.1-cp312-cp312-macosx_10_15_x86_64.whl
| Download URL | lunapi-1.7.1-cp312-cp312-macosx_10_15_x86_64.whl |
|---|---|
| Size | 16.9 MB |
| Tags | CPython 3.12 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
7a23d7b3f69224c47e4212d0a6b1c1579bcfa1407482344346dfb0ace2399a09
|
|
BLAKE2b-256 checksum How to use checksums |
83fc4f5a9f4acafcbe9dfb7fb406d31c93986c03f0e20574881f8dcf9d4c35d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / lunapi-1.7.1-cp311-cp311-win_amd64.whl
| Download URL | lunapi-1.7.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 12.2 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
28235f52c247ea45f942e4872f4bb6cbeb365f3f6f5211c12c83846a4d30e73b
|
|
BLAKE2b-256 checksum How to use checksums |
f163035d2bd8ae3330d2239ead1e47d1474b69a5042c5ff9792d520d0b30a3b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.17
|
Release files / lunapi-1.7.1-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | lunapi-1.7.1-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 14.5 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
082a4a391ef88d1f8266b8bbaac5fcf96a93bade519852efc808908ffaa81cc7
|
|
BLAKE2b-256 checksum How to use checksums |
6f742f3606c501ec21b8d1b6aaa8459dd7a75f6bca38b476b6c40979f6a8abff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / lunapi-1.7.1-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | lunapi-1.7.1-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 14.9 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c10be395762e0f961ee2ae867b53f81fdd90d9f816529b0d9e379d9df98132a6
|
|
BLAKE2b-256 checksum How to use checksums |
db7e134a5cedab21f5f2096606fac942352f1dc60bd9a0295c1caa48d72bc1dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / lunapi-1.7.1-cp311-cp311-macosx_10_15_x86_64.whl
| Download URL | lunapi-1.7.1-cp311-cp311-macosx_10_15_x86_64.whl |
|---|---|
| Size | 16.9 MB |
| Tags | CPython 3.11 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
cee0705e6f30be6decaebc59a58d77e8da28e7968d85510fe9cbf5c233593789
|
|
BLAKE2b-256 checksum How to use checksums |
224ef606f65bb6e46c83060f529b88a1915c8cb14cf3e17ae23b62ef599b9158
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / lunapi-1.7.1-cp310-cp310-win_amd64.whl
| Download URL | lunapi-1.7.1-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 12.1 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
bddfc42221efe7f9d0758f687fa788a0d90aa970f585177154b93b16a8b5c31b
|
|
BLAKE2b-256 checksum How to use checksums |
a477ead0666d751d6ba946cf314eccf64fbac0a253739d78faf60c119bac2396
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.17
|
Release files / lunapi-1.7.1-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | lunapi-1.7.1-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 14.5 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
211195bffd50d8ae88b2b111ea410f26d368b273ecb5a25c84f433a304a26ce1
|
|
BLAKE2b-256 checksum How to use checksums |
0ba6edda48b15395ba09aef33666195e6990727f40942077c8fdc3478dcf2aca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / lunapi-1.7.1-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | lunapi-1.7.1-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 14.9 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8205792d94fe2561f8b5407d678101c5eb6234d7b12ccedcaac585e91f6a270b
|
|
BLAKE2b-256 checksum How to use checksums |
57a91f8734c7f419cfd513faf36f5d8799b9ceb59596f02ea055f24096b99eb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / lunapi-1.7.1-cp310-cp310-macosx_10_15_x86_64.whl
| Download URL | lunapi-1.7.1-cp310-cp310-macosx_10_15_x86_64.whl |
|---|---|
| Size | 16.9 MB |
| Tags | CPython 3.10 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
d52293e8d076a4aba096209c412e2dbf7a67744403fba458609992c9156673da
|
|
BLAKE2b-256 checksum How to use checksums |
e4165c2dcda0a169e61cdbeb2787cc0e17167712f12ced0d17d6371d75fc041a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / lunapi-1.7.1-cp39-cp39-win_amd64.whl
| Download URL | lunapi-1.7.1-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 12.1 MB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0b9a4160108c8bf33903d07661c593d7d78659edf7e9d0f1a4f35dff743a9f8a
|
|
BLAKE2b-256 checksum How to use checksums |
84312b62adb8afb721455d9aa0f340e0f39ac7466eaa69f2c2648e03e32a1e9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.17
|
Release files / lunapi-1.7.1-cp39-cp39-manylinux_2_28_x86_64.whl
| Download URL | lunapi-1.7.1-cp39-cp39-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 14.5 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
35c7a418f353582d49495093bf8024f08612cf39cbeba098689b64491dc93781
|
|
BLAKE2b-256 checksum How to use checksums |
762e09056b6224bb552073f611992d713f439d7b6379fbc5fdb38ffa3daacda4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / lunapi-1.7.1-cp39-cp39-macosx_11_0_arm64.whl
| Download URL | lunapi-1.7.1-cp39-cp39-macosx_11_0_arm64.whl |
|---|---|
| Size | 14.9 MB |
| Tags | CPython 3.9 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6ac8a9fb57763ef9d243a569f117d1fffa5cabe04200a0b79b985a528b782567
|
|
BLAKE2b-256 checksum How to use checksums |
f819f7ab79325e43d2fa899cca6d6979660633a7181800d2535244e6dd803de3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / lunapi-1.7.1-cp39-cp39-macosx_10_15_x86_64.whl
| Download URL | lunapi-1.7.1-cp39-cp39-macosx_10_15_x86_64.whl |
|---|---|
| Size | 16.9 MB |
| Tags | CPython 3.9 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
e20a6793117a14193803364488e7ad6b7dee46a2da21c5f5df3a86f726f21f3f
|
|
BLAKE2b-256 checksum How to use checksums |
36a8a5b17c9610ecea751b13cc32dc5f125ed37f3053212e57f8ece9e88ad898
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Security for lunapi 1.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.