_..._ _..._ _..._ _..._ _..._
.:::::::. .::::. `. .:::: `. .::' `. .' `.
::::::::::: :::::::. : :::::: : ::: : : :
::::::::::: :::::::: : :::::: : ::: : : :
`:::::::::' `::::::' .' `::::: .' `::. .' `. .'
`':::'' `'::'-' `'::.-' `':..-' `-...-'
_..._ _..._ _..._ _..._ _..._
.' `. .' `::. .' ::::. .' .::::. .:::::::.
: : : ::: : :::::: : :::::::: :::::::::::
: : : ::: : :::::: : :::::::: :::::::::::
`. .' `. .::' `. :::::' `. '::::::' `:::::::::'
`-...-' `-..:'' `-.::'' `-.::'' `':::''
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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| moon-3.0.0.tar.gz | 9.8 kB | Without provenance | Details for moon-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| moon-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for moon-3.0.0-py3-none-any.whl |
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
|
Security for moon 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.