Skip to main content

A Python library for sleep pattern analysis, sleep metrics calculation, and comprehensive sleep stage statistics

Project description

pysleep

A Python library for sleep pattern analysis and sleep metrics calculation commonly used in medical and research fields.

Installation

pip install pysleep

Features

  • Definition of sleep stages and events in the Python ecosystem
  • Various sleep metrics used in medical field
  • Sleep statistics calculation and analysis tools
  • Comprehensive sleep stage calculator for 30+ metrics from epoch data
  • Returns None for breathing fields (requires sensor data)
  • Returns None for sleep_index (scoring not implemented)

Sleep Stage Calculator

The SleepStageCalculator analyzes 30-second epoch sleep stage data to compute comprehensive sleep metrics including latencies, durations, ratios, and sleep quality indices.

Quick Example

from pysleep import SleepStageCalculator
from datetime import datetime

# Initialize calculator
calculator = SleepStageCalculator()

# Define session times
start_time = datetime(2024, 1, 1, 22, 0, 0)
end_time = datetime(2024, 1, 2, 6, 0, 0)

# Sleep stages (30-second epochs): 0=WAKE, 1=LIGHT, 2=DEEP, 3=REM
sleep_stages = [0, 0, 1, 1, 2, 2, 3, 3, 1, 1, 0, 1, 2, 3]  # ... more epochs

# Calculate metrics
stats = calculator.calculate(sleep_stages, start_time, end_time)

# Access results (returns SleepStat object)
print(f"Sleep efficiency: {stats.sleep_efficiency:.1%}")
print(f"Time in sleep: {stats.time_in_sleep}")
print(f"Sleep latency: {stats.sleep_latency}")
print(f"Sleep cycles: {stats.sleep_cycle}")

For detailed documentation on all available metrics and advanced usage, see the Sleep Stage Calculator documentation.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pysleep-0.2.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

pysleep-0.2.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file pysleep-0.2.0.tar.gz.

File metadata

  • Download URL: pysleep-0.2.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pysleep-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c849fb88943f0e11891833915cae5cb1dbab243805a6da5c1a8ccb50997d4032
MD5 1dc3f6d8a93747ad4d29731b24562f46
BLAKE2b-256 084f1ce1e82040f01dbeeb26f3fd94541e0618ea2605c2846ef3347d5ec71384

See more details on using hashes here.

File details

Details for the file pysleep-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pysleep-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pysleep-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 840952cd99033e174bbfc282d8391e76ab487120e8743b9edb19b3d01c1fde5b
MD5 bd748bfcbf91aed4f9ff6502a9d310b6
BLAKE2b-256 f30ca3f8dbb03ba2caf2dfb4cbf53475c98dd2ae20367bc842b04345825e5656

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