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.

Download files

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

Source Distribution

moon-3.0.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

moon-3.0.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file moon-3.0.0.tar.gz.

File metadata

  • Download URL: moon-3.0.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.3

File hashes

Hashes for moon-3.0.0.tar.gz
Algorithm Hash digest
SHA256 13f62aed117566b4f3e8c55921d1c7fc67f24dbbc388c586a25522a1bfd888d1
MD5 a806e2f40dbb93cf3e99e003bd7067f8
BLAKE2b-256 af3d880a496ee836f66343943004e63c6e106b9dc8fbeaf55e4ceb2778321674

See more details on using hashes here.

File details

Details for the file moon-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: moon-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.3

File hashes

Hashes for moon-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0ea87feacd2c8bff52dc8b8cb30d9d86f06090eb1a5c5dfdf0eceba3ed473b6
MD5 e0757092122e35f209cd5e24cdee1f27
BLAKE2b-256 38fe244140edbed38a73a9fca33ea8768bc1ec97e442e952e6a619f73be1a1bc

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 files

2.0.0

1 file

1.1.9

1 file

1.1.8

1 file

1.1.7

1 file

1.1.6

1 file

1.1.5

1 file

1.1.4

1 file

1.1.3

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.9

1 file

1.0.8

1 file

1.0.7

1 file

1.0.6

1 file

1.0.5

1 file

1.0.4

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0

1 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