skygrad
Realistic sky gradient PNGs from latitude, longitude, and time. Zenith at
the top, horizon at the bottom — one color per row, or the sun's glow
lobe across the frame when you pass facing. The sun's position
drives every color in the image; the sun itself is never drawn — no disc,
no moon, no stars, no clouds. Zero runtime dependencies.
Usage
from datetime import datetime
import skygrad
# One-shot PNG bytes
png = skygrad.render(lat=34.05, lon=-118.24,
when=datetime(1994, 6, 21, 19, 30),
width=512, height=1024)
# Or write straight to a file
skygrad.write_png("dusk.png", lat=34.05, lon=-118.24,
when=datetime(1994, 6, 21, 19, 30))
# Layered access: colors without pixels
sky = skygrad.Sky.at(lat=34.05, lon=-118.24, when=datetime(1994, 6, 21, 19, 30))
sky.solar_elevation # degrees; e.g. streetlights on below -4
sky.color(0.0) # (r, g, b) at the zenith; 1.0 is the horizon
sky.stops() # [(u, (r, g, b)), ...] — build a CSS gradient
Facing (azimuthal glow)
Pass a compass direction and the image gains the sun's glow lobe —
brightest toward the sun, fading with angular distance, gone when you
face away. Without facing, output is byte-identical to skygrad 0.1.
sky = skygrad.Sky.at(lat=34.05, lon=-118.24, when=datetime(1994, 6, 21, 19, 40))
sky.solar_azimuth # ≈ 303° at this dusk — west-northwest
toward = sky.png(facing=sky.solar_azimuth) # sunset glow, centered
away = sky.png(facing=(sky.solar_azimuth + 180) % 360) # plain dusk gradient
wide = sky.png(facing=0.0, fov=360.0, width=2048) # full panorama strip
facing is degrees clockwise from true north (any finite value,
normalized mod 360; radians callers use math.degrees()). fov is the
horizontal span in degrees, default 90, valid (0, 360] — and requires
facing.
A facing render is computed per pixel, so it's capped at ~4 million pixels
(width × height ≤ 2048×2048); go larger and it raises ValueError. Tile,
shrink, or drop facing (the plain vertical gradient is per-row and has no
such cap). Requires Python 3.11+.
Time semantics (read this)
when is a full datetime — the date matters (June and December at the
same hour give completely different skies).
- Timezone-aware datetimes are honored exactly.
- Naive datetimes mean local mean solar time at the given longitude: sundial time, where 12:00 puts the sun on the meridian. This is deliberate — it makes "local" meaningful for fictional places — but it can differ from civil wall-clock time by an hour or more. If you want wall-clock local time, attach a tzinfo.
Determinism
Same inputs → same decoded pixels for a given skygrad.MODEL_VERSION
(and byte-identical PNGs within one zlib build). MODEL_VERSION bumps
whenever any input would render different colors, so golden tests in
consumers break deliberately, never silently. Compare decoded pixels,
not compressed bytes.
Development
uv sync
uv run ruff check . && uv run ruff format --check .
uv run mypy
uv run pytest -q
Golden skies are pinned under tests/golden/; regenerate deliberately
with uv run pytest --regen-golden and bump MODEL_VERSION if colors
changed. Regeneration rewrites all ten goldens, but on one zlib build the
untouched ones are byte-identical rewrites — so a deliberate single-color
change surfaces as exactly the goldens it should. The module map and
invariants live in ARCHITECTURE.md, and the design
rationale (theory of operation) in THEORY.md.
Metadata
Release files for skygrad 1.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 | |
|---|---|---|---|
| skygrad-1.0.0.tar.gz | 167.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| skygrad-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 184.6 kB
Release files / skygrad-1.0.0.tar.gz
| Download URL | skygrad-1.0.0.tar.gz |
|---|---|
| Size | 167.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e77b266534f16c8b455e83e73e4cee4d083f611d5284b33ad8ee3b67c01dc9e7
|
|
BLAKE2b-256 checksum How to use checksums |
55570d7359c2bc1adfaa3102d9e54599caad693c2574a2c89d28368eb59992c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.
Transparency logRelease files / skygrad-1.0.0-py3-none-any.whl
| Download URL | skygrad-1.0.0-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
407f3be37857a2ade08a337c5adc230958c1c45cf03850e874a785e6ea930d0c
|
|
BLAKE2b-256 checksum How to use checksums |
b3a0d0efd61573d8dbabe2163fb66fd81011a1051bb404645eb3cbe75e73bd11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.
Transparency log