suntime
Simple sunset and sunrise time calculation python library
What it is and what it does
SunTime is a lightweight Python library that computes sunrise and sunset times for any geographic location and date. It takes latitude and longitude as input and returns datetime objects representing when the sun rises and sets, either in UTC or in a specified local timezone. The library handles the mathematical complexity of solar position calculations internally, so you don't need to implement the astronomy yourself.
The main use case is applications that need to know daylight hours—weather apps, scheduling systems, outdoor activity planners, or any tool that must adapt behavior based on solar events. It includes error handling for edge cases like polar regions where the sun may not rise or set on certain dates, raising SunTimeException when these conditions occur. The library depends only on python-dateutil for timezone handling.
Use it for:
- Determine daylight hours for a given location and date in a weather or outdoor activity app
- Schedule tasks or alerts to trigger at sunrise or sunset in a user's local timezone
- Calculate solar noon or twilight times for photography, astronomy, or solar energy applications
- Validate whether a location experiences midnight sun or polar night on a specific date
- Build a calendar or scheduling UI that highlights daylight and darkness periods
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Calculates sunrise and sunset times for any geographic location and date, handling edge cases like polar regions where the sun may not rise or set.
Yes, if you need straightforward sunrise/sunset calculations. The library is simple, has low install friction, no known vulnerabilities, and a stable API. However, maintenance is dormant—no updates since March 2024—so if you need active support or frequent bug fixes, consider whether this is acceptable for your use case. The LGPLv3 license is permissive for most projects but requires attention if you're building proprietary software.
Install
suntime on PyPI
pip
pip install suntimeuv
uv add suntimepoetry
poetry add suntimeInstalling suntime
Before you install
Low friction: pure Python wheel with a single runtime dependency on python-dateutil. Last release was in March 2024; the repository is dormant but not archived, with no recent activity to suggest active maintenance.
License in practice
Licensed under LGPLv3 (copyleft). You may use and modify the library freely, but any derivative work must also be distributed under LGPLv3 or a compatible license.
Quickstart
pip install suntime
from suntime import Sun
import datetime
sun = Sun(51.21, 21.01) # Warsaw coordinates
today_sr = sun.get_sunrise_time()
today_ss = sun.get_sunset_time()
print(f'Sunrise: {today_sr}, Sunset: {today_ss}')
Verify before relying
- Accuracy of calculations and whether they match standard astronomical references
- Whether polar-region edge cases (midnight sun, polar night) are handled correctly in all scenarios
- Current maintenance status and likelihood of bug fixes or updates
Package facts
| License | LGPLv3 (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — python-dateutil |
| Maintenance | dormant — 887 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 212,778/month — #9,451 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: suntime-1.3.2-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
suntimesCalculates sunrise and sunset times for any…
permissive · top 15,000 on PyPI
pytzpytz brings the Olson timezone database into…
permissive · top 100 on PyPI
tzfpyConverts geographic coordinates…
permissive · top 5,000 on PyPI
sunpySunPy provides Python tools for accessing,…
permissive · top 15,000 on PyPI
backports.zoneinfoProvides IANA time zone support for Python…
permissive · top 5,000 on PyPI
arrowArrow provides a simpler, more intuitive API…
permissive · top 1,000 on PyPI
lunardateConverts between Gregorian (solar) and Chinese…
copyleft · top 5,000 on PyPI
momentA Python library for parsing, manipulating, and…
permissive · top 15,000 on PyPI
tzwhereLooks up the IANA timezone name for a given…
permissive · top 15,000 on PyPI
airporttimeConverts between local time and UTC for any…
unclear · top 15,000 on PyPI