Skip to main content

SunTime

Simple sunset and sunrise time calculation python library.

Installation

Using pip:

pip3 install suntime

Or download and type:

python3 setup.py install

Usage

You can use the library to get UTC and local time sunrise and sunset times typing:

import datetime
from dateutil import tz
from suntime import Sun, SunTimeException

warsaw_lat = 51.21
warsaw_lon = 21.01

sun = Sun(warsaw_lat, warsaw_lon)

# Get today's sunrise and sunset in UTC
today_sr = sun.get_sunrise_time()
today_ss = sun.get_sunset_time()
print('Today at Warsaw the sun raised at {} and get down at {} UTC'.
      format(today_sr.strftime('%H:%M'), today_ss.strftime('%H:%M')))

# On a special date in your machine's local time zone
abd = datetime.datetime(2014, 10, 3)
abd_sr = sun.get_sunrise_time(abd, tz.gettz('Europe/Warsaw'))
abd_ss = sun.get_sunset_time(abd, tz.gettz('Europe/Warsaw'))
print('On {} the sun at Warsaw raised at {} and get down at {}.'.
      format(abd, abd_sr.strftime('%H:%M'), abd_ss.strftime('%H:%M')))

# Error handling (no sunset or sunrise on given location)
latitude = 87.55
longitude = 0.1
sun = Sun(latitude, longitude)
try:
    abd_sr = sun.get_sunrise_time(abd)
    abd_ss = sun.get_sunset_time(abd)
    print('On {} at somewhere in the north the sun raised at {} and get down at {}.'.
          format(abd, abd_sr.strftime('%H:%M'), abd_ss.strftime('%H:%M')))
except SunTimeException as e:
    print("Error: {0}.".format(e))

Testing

To run the tests, type:

pytest tests.py

For linting checks, type:

ruff check .

Authors

Started by SatAgro Sp. z o.o. and improved by our awesome contributors:

License

This file is part of SunTime library for python (SunTime).

SunTime is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

SunTime is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with CAMS tools. If not, see http://www.gnu.org/licenses/.

Metadata

Release files for suntime 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for suntime 1.4.0
File Size Uploaded
suntime-1.4.0.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for suntime 1.4.0
File Interpreter ABI Platform
suntime-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / suntime-1.4.0.tar.gz

Download URL suntime-1.4.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a9808c5d20b7d2ae0b05d8acb3f5f28737ed32c0eb7e7c8411d5e22698a29128
BLAKE2b-256 checksum
How to use checksums
3b3f2c4878db5b99afd0ac4a26d100b350c20b90b7fce49570ffa93d2c6f4899
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / suntime-1.4.0-py3-none-any.whl

Download URL suntime-1.4.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da2ffd1535e52a486f8caf4b9176ab8d23fca94def23ccf127ab9f82ff2a2ff3
BLAKE2b-256 checksum
How to use checksums
b6299f9937f87da797ed15a4bd3a046715c17d12929888cb073cdab13ce58c4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.5

3 release files

1.2.4

2 release files

1.2.1

2 release files

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