Skip to main content

Python interface to the Luna toolset for sleep signal analysis

Project description

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 pandas DataFrames keyed by command and stratum
  • SQLite result stores — write output to .db files 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())

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

lunapi-1.6.5-cp314-cp314-win_amd64.whl (11.8 MB view details)

Uploaded CPython 3.14Windows x86-64

lunapi-1.6.5-cp314-cp314-manylinux_2_28_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

lunapi-1.6.5-cp314-cp314-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

lunapi-1.6.5-cp314-cp314-macosx_10_15_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64

lunapi-1.6.5-cp313-cp313-win_amd64.whl (11.5 MB view details)

Uploaded CPython 3.13Windows x86-64

lunapi-1.6.5-cp313-cp313-manylinux_2_28_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

lunapi-1.6.5-cp313-cp313-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

lunapi-1.6.5-cp313-cp313-macosx_10_14_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.13macOS 10.14+ x86-64

lunapi-1.6.5-cp312-cp312-win_amd64.whl (11.5 MB view details)

Uploaded CPython 3.12Windows x86-64

lunapi-1.6.5-cp312-cp312-manylinux_2_28_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

lunapi-1.6.5-cp312-cp312-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lunapi-1.6.5-cp312-cp312-macosx_10_14_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.12macOS 10.14+ x86-64

lunapi-1.6.5-cp311-cp311-win_amd64.whl (11.5 MB view details)

Uploaded CPython 3.11Windows x86-64

lunapi-1.6.5-cp311-cp311-manylinux_2_28_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

lunapi-1.6.5-cp311-cp311-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lunapi-1.6.5-cp311-cp311-macosx_10_14_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.11macOS 10.14+ x86-64

lunapi-1.6.5-cp310-cp310-win_amd64.whl (11.5 MB view details)

Uploaded CPython 3.10Windows x86-64

lunapi-1.6.5-cp310-cp310-manylinux_2_28_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

lunapi-1.6.5-cp310-cp310-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

lunapi-1.6.5-cp310-cp310-macosx_10_14_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.10macOS 10.14+ x86-64

lunapi-1.6.5-cp39-cp39-win_amd64.whl (11.5 MB view details)

Uploaded CPython 3.9Windows x86-64

lunapi-1.6.5-cp39-cp39-manylinux_2_28_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

lunapi-1.6.5-cp39-cp39-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

lunapi-1.6.5-cp39-cp39-macosx_10_14_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

File details

Details for the file lunapi-1.6.5-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: lunapi-1.6.5-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 11.8 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for lunapi-1.6.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 58d5932c55c426d4532214380ce0fd3e886cb13888ad06691e79303b53c63a71
MD5 17f5ac7cdf81812e9ead34dab7e91ff5
BLAKE2b-256 de76e05e351a1a9bf720c738cc3b3819f05ee7517bdc1ce513f79e957eb132dd

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d5be0832c33a491322ce6c3818af572535109a99c37cd1e457e74ff95b097dd6
MD5 ec5d743e2dbcec9eadc349c3023ec267
BLAKE2b-256 322df28d5615054560578c58cac8a8709357efa15cde7d387b2402c4a0912e68

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7fccc9dd0fba45230dc14e34a0c6b0217e6ca3cd7c7094c432e8a481964ed07
MD5 a36bf6c03c7ce5a66e9557675e302f02
BLAKE2b-256 dcd3fdac1baa0841e9e9d7e7643a42adec4585bef24f670eea3042fb8b233c84

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp314-cp314-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1f311ceb94ce20a9d6b5b83db03987ac3034769de6dd81f66d9bf36b53051aa2
MD5 08326f9499512dc54eaf9c53e116168c
BLAKE2b-256 0a33cf019bf51639e55198f7c3f9cd42afe5bb50f805527f9feaf88e71936af4

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: lunapi-1.6.5-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 11.5 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for lunapi-1.6.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 43c9080382444252e3369e27017be128fbbdfe0c1f11d77ee5b9cefdb5993fd2
MD5 e9f6acc459552203c75cf6f4039de0a7
BLAKE2b-256 a8bd0027948627c20d6c69742c9f5a172cf71987e561727b44d31cb5bce6598e

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 23500ce780dc3d9eedd7daa8655d5fd66ab2a5ebd1c870045f4049e570a2d9c4
MD5 7e458642b7dc4029f3188b2d926beab9
BLAKE2b-256 6066caf739a91dd62abb5fe2c2de65152e1fb007bf37f7c7dbe7f5b514459d95

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 527aabbc64a3534cc318db9b449e608a7e79010ead99b08550b31e69f173c094
MD5 9c2a5cbe3da1532106008177adaced9a
BLAKE2b-256 8b4dd0cfe7dd7634177d026f83780e621e45a905fe8ac47bdd42d4069096266b

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp313-cp313-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp313-cp313-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6642785c478da574fe657b1d05f9b3abc6c6a6fd43a71f0fafee2e0eec0f65e4
MD5 7e5b59ff178d64ec87be6c8f062e89a6
BLAKE2b-256 1e4598b0a87ce2ad09b904c1b970d8e2731c002a3ba203c6f1c541a1383a4346

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: lunapi-1.6.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 11.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for lunapi-1.6.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f11e67fada04244379be5e9e81b13d8ac740657499e73f907894e7a73a737949
MD5 a961f8db44be572dd7aeff49e2d98184
BLAKE2b-256 fd8b1ee64e1c5f2fc698162ce0704ce1914b23c2a2990d889f9021a53e7df220

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4296ca0e304679c5ccddd693ca7a20db13df02504b2e16a150e464223406d887
MD5 d51dd58bee7479d2b05bdcde1f85a0c3
BLAKE2b-256 7e55daeceebc5dcdc62f2e79ba4613fe41c0747996a970e87b072be8797ede21

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 494d4fdb1f96c339fba9bb9dee5f5ee73e86e45f91286e431ae13b0a5a21a9f6
MD5 d85490a6cbcda14316cc38379b15adb4
BLAKE2b-256 2dff86024d6c7375d095b39d53fae2a56553b8d8b719150a1bc65f1bdd7d701e

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp312-cp312-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp312-cp312-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6b9814cc8318f9b4f5bcefbfba37432fd6622cf956f7f73253d819fa0c038118
MD5 44f2f96a6a2171099c02151f91cb7c8b
BLAKE2b-256 81812bc62021ef0da0b02f7623c8796b2f672369e1d9b342243b4609595a7230

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: lunapi-1.6.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 11.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for lunapi-1.6.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2e35c54218df826c506cb84a49bd5951e90ebeed1bc1b5ae99ce4aea508bd562
MD5 b71d490ae0f8d4e8a3fb598085d95c8c
BLAKE2b-256 8ae83eba7a43298d99ba2d01b5fdb9f0f8dcda6d17f7e85494439104bb882642

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f2a2602e13ff532189e4ebcf3817a0022bf85251198c0f41df7d3d0115dce285
MD5 75402523d403e6c2b1a4a0ab4e9b2087
BLAKE2b-256 08343fbfdb284955cdfd64d12e92bd191020cc29c25e423d1389ff15cc2e5f00

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7de24916fdbfdb92c0eae5d45567480451f4d9a77574292ce3a7878fd6f09947
MD5 11b55d3d784dce4ed4a0457c9cd4fa0b
BLAKE2b-256 2395c0809b63e01c368dbb516e59e37e0ed3eff0770d732fdd22042850d83395

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 771953737f57bee59c118dd6c948c423c13ed87b8b3d3218e547054e40e099a0
MD5 3409e9c55ae930cd5ea2dc9d8003d14a
BLAKE2b-256 ba8763220fa20c945d9105c892bbc4a1b1de6b3b32149b7ed1981d21653f5711

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: lunapi-1.6.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 11.5 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for lunapi-1.6.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f2e1302c965ce71d17f0d6f29b51c24d622791bfe1add4536234cb197c54e44b
MD5 fdde580bad971c1f44216c4196c061e2
BLAKE2b-256 545b29dd53553026fca739caee5a8ba70bfcf914200db1eb8102df7410b7d37e

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 848b59c705fbd12a554dde55fa3c603d93937e69e0b52c25bdecb89d011e574c
MD5 3b4b3fb643d3acf09f5ed678916b4e92
BLAKE2b-256 befa54dcc67ad56bb8eaff27591507508d5d195ceeda246b344fd7338de0fdbe

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 586871306dbaed2ac64841b5f2752a9be87b0046d131ea8e5362b6b20e37171e
MD5 4b52f0ca11c6509e681c315ee7a7ce56
BLAKE2b-256 7beb27b4a10fda6b67f9fc5db2b015cc1ec8ca712fcece373de5c1d2b934b364

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 c3aa1fb84c6efd64b5f9d9dcf7d5dad6a1dd383152bea8d6f932ced523a71907
MD5 8a499ac051bb0b5a263af335f41a29fd
BLAKE2b-256 cd182c42b4fe38d9d6da3a43f553e7c69048952ef15973d2f9cd057f683a4a28

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: lunapi-1.6.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 11.5 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for lunapi-1.6.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7815dbf6b83a79cdaf8b8c35727beb10b5edb0e9f315c07335f33c9f0586d4dc
MD5 59d55fecc89eee4e59eab04cf75f730d
BLAKE2b-256 d0d299100a571d08373836868c06cb30ae3cc21baa06e2733d9bf2846739903b

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 651b5c782079bc49faed294ea54558ceb9fc3c448a8a36f0bf6b7e0b0f3198a9
MD5 fccd5095dd3092ebfa51b8c6ea297902
BLAKE2b-256 e7eaa95fc4f964d2c18d3135a8c072f24290aa0edc5c248c73b752d3b4e68136

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35cf9e5ae2751961cbae1ae94dc5b81acbafc538bcfbce731e2a52bb4e3d367c
MD5 005f0f28ff1352d19e2416a275faeebc
BLAKE2b-256 6d228f16ee050837809b9bb9e33c1e1769af94c0f8126d0e72ba453b72daef4e

See more details on using hashes here.

File details

Details for the file lunapi-1.6.5-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lunapi-1.6.5-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 4f216bcc1044d12c901e569e49226fe09dafd698505e3a5cab06b54794dca6f0
MD5 1fe64daceac8411f1517a437bc9d47e1
BLAKE2b-256 20d82cf89cbe229298a3f6bde2d57220990229bb11fe8d52212bd9c194dcd5d3

See more details on using hashes here.

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