_..._ _..._ _..._ _..._ _..._
.:::::::. .::::. `. .:::: `. .::' `. .' `.
::::::::::: :::::::. : :::::: : ::: : : :
::::::::::: :::::::: : :::::: : ::: : : :
`:::::::::' `::::::' .' `::::: .' `::. .' `. .'
`':::'' `'::'-' `'::.-' `':..-' `-...-'
_..._ _..._ _..._ _..._ _..._
.' `. .' `::. .' ::::. .' .::::. .:::::::.
: : : ::: : :::::: : :::::::: :::::::::::
: : : ::: : :::::: : :::::::: :::::::::::
`. .' `. .::' `. :::::' `. '::::::' `:::::::::'
`-...-' `-..:'' `-.::'' `-.::'' `':::''
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
urllibwithrequests - Type hints and
py.typedmarker Moonno longer requires a subclass for basic use- Reimplemented
TerminalUiwith 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.imageis now RGB (was BGR when using OpenCV). If you were passingmoon.imageback into OpenCV, swap channels withcv2.cvtColor(m.image, cv2.COLOR_RGB2BGR). - Breaking:
moon.custom_image.CustomImageandmoon.res.constantsare 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_cachebug (#4)
1.1.2 (2021-01-24)
Moon.set_moon_phase()accepts anhourparameter
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13f62aed117566b4f3e8c55921d1c7fc67f24dbbc388c586a25522a1bfd888d1
|
|
| MD5 |
a806e2f40dbb93cf3e99e003bd7067f8
|
|
| BLAKE2b-256 |
af3d880a496ee836f66343943004e63c6e106b9dc8fbeaf55e4ceb2778321674
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0ea87feacd2c8bff52dc8b8cb30d9d86f06090eb1a5c5dfdf0eceba3ed473b6
|
|
| MD5 |
e0757092122e35f209cd5e24cdee1f27
|
|
| BLAKE2b-256 |
38fe244140edbed38a73a9fca33ea8768bc1ec97e442e952e6a619f73be1a1bc
|