Skip to main content
        _..._           _..._            _..._            _..._            _..._
      .:::::::.       .::::. `.        .::::  `.        .::'   `.        .'     `.
     :::::::::::     :::::::.  :      ::::::    :      :::       :      :         :
     :::::::::::     ::::::::  :      ::::::    :      :::       :      :         :
     `:::::::::'     `::::::' .'      `:::::   .'      `::.     .'      `.       .'
       `':::''         `'::'-'         `'::.-'           `':..-'          `-...-'

        _..._           _..._           _..._            _..._            _..._
      .'     `.       .'   `::.       .'  ::::.        .' .::::.        .:::::::.
     :         :     :       :::     :    ::::::      :  ::::::::      :::::::::::
     :         :     :       :::     :    ::::::      :  ::::::::      :::::::::::
     `.       .'     `.     .::'     `.   :::::'      `. '::::::'      `:::::::::'
       `-...-'         `-..:''         `-.::''          `-.::''          `':::''

moon

A Python package that fetches moon-phase images from NASA's Dial-a-Moon API, based on Ernie Wright's visualizations at NASA's Scientific Visualization Studio.

Any UTC date and hour supported by the Dial-a-Moon API works (currently 2011 onward).

Installation

pip install moon

Optional Jupyter support:

pip install "moon[jupyter]"

Usage

from moon import Moon

m = Moon()
m.set_moon_phase()                    # defaults to now (UTC)
# m.set_moon_phase(date="2025-03-14", hour=12)

m.image           # numpy.ndarray, RGB uint8, shape (730, 730, 3)
m.info            # full API response: phase, distance, illumination, etc.
m.url             # source image URL
m.save()          # writes moon-image-YYYYMMDD.jpg to CWD

Resize by passing size to the constructor:

m = Moon(size=(100, 100))

In a Jupyter notebook:

from moon.jupyter_ui import JupyterUi

ui = JupyterUi()
ui.set_moon_phase()
ui.show()

In a terminal (Unicode half-blocks with truecolor, ASCII fallback):

from moon.terminal_ui import TerminalUi

ui = TerminalUi()
ui.set_moon_phase()
ui.show()                     # auto-detects truecolor support
ui.show(mode="ascii")         # force ASCII
ui.show(mode="blocks", width=60)

m.info includes fields like phase, age, distance, diameter, subsolar_lon, subsolar_lat, plus a image_highres URL if you want a larger version. See the Dial-a-Moon API docs.

Development

pip install -e ".[dev]"
pytest                    # unit tests only
pytest -m integration     # hit the real NASA API

Changelog

3.0.0 (2026)

  • Modernized packaging: pyproject.toml (PEP 621), Python 3.10+
  • Replaced OpenCV with Pillow (~50 MB → ~3 MB dependency)
  • Replaced urllib with requests
  • Type hints and py.typed marker
  • Moon no longer requires a subclass for basic use
  • Reimplemented TerminalUi with Unicode half-block truecolor rendering + ASCII fallback (was a deprecation stub in 2.0.0)
  • Removed stale SVS-ID year lookup
  • pytest test suite with mocked HTTP; opt-in integration tests
  • GitHub Actions CI across Python 3.10–3.13
  • Breaking: moon.image is now RGB (was BGR when using OpenCV). If you were passing moon.image back into OpenCV, swap channels with cv2.cvtColor(m.image, cv2.COLOR_RGB2BGR).
  • Breaking: moon.custom_image.CustomImage and moon.res.constants are removed.

2.0.0 (2024-02-01)

  • Use the Dial-a-Moon API to determine image URLs (no more yearly SVS ID updates)
  • Deprecate terminal image viewing

1.1.5 (2021-12-30)

  • Move constants to .json, add 2022 SVS ID, fallback to GitHub constants when a year is missing

1.1.3 (2021-05-01)

  • Update numpy and opencv-python versions, fix lru_cache bug (#4)

1.1.2 (2021-01-24)

  • Moon.set_moon_phase() accepts an hour parameter

Resources

Moon ASCII art courtesy of jsg.

Release files for moon 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moon 3.0.0
File Size Uploaded
moon-3.0.0.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moon 3.0.0
File Interpreter ABI Platform
moon-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.5 kB

Release files / moon-3.0.0.tar.gz

Download URL moon-3.0.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
13f62aed117566b4f3e8c55921d1c7fc67f24dbbc388c586a25522a1bfd888d1
BLAKE2b-256 checksum
How to use checksums
af3d880a496ee836f66343943004e63c6e106b9dc8fbeaf55e4ceb2778321674
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.3

Release files / moon-3.0.0-py3-none-any.whl

Download URL moon-3.0.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0ea87feacd2c8bff52dc8b8cb30d9d86f06090eb1a5c5dfdf0eceba3ed473b6
BLAKE2b-256 checksum
How to use checksums
38fe244140edbed38a73a9fca33ea8768bc1ec97e442e952e6a619f73be1a1bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.3

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.0.0

1 release file

1.1.9

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page