Skip to main content

Welcome to Astral V0.5

Astral is a python module for calculating the times of various aspects of the sun and moon.

It calculates the following

Dawn

The time in the morning when the sun is a specific number of degrees below the horizon.

Sunrise

The time in the morning when the top of the sun breaks the horizon (asuming a location with no obscuring features.)

Solar Noon

The time when the sun is at its highest point.

Sunset

The time in the evening when the sun is about to disappear below the horizon (asuming a location with no obscuring features.)

Dusk

The time in the evening when the sun is a specific number of degrees below the horizon.

Solar Azimuth

The number of degrees clockwise from North at which the sun can be seen

Solar Elevation

The number of degrees up from the horizon at which the sun can be seen

Rahukaalam

“Rahukaalam or the period of Rahu is a certain amount of time every day that is considered inauspicious for any new venture according to Indian astrology”.

Moon Phase

Calculates the phase of the moon for a specified date.

Example

The following example demonstrates the functionality available in the module

>>> import datetime
>>> from astral import Astral

>>> city_name = 'London'

>>> a = Astral()
>>> a.solar_depression = 'civil'

>>> city = a[city_name]

>>> print('Information for %s/%s\n' % (city_name, city.country))
Information for London/England

>>> timezone = city.timezone
>>> print('Timezone: %s' % timezone)
Timezone: Europe/London

>>> print('Latitude: %.02f; Longitude: %.02f\n' % \
>>>     (city.latitude, city.longitude))
Latitude: 51.60; Longitude: 0.08

>>> sun = city.sun(date=datetime.date(2009, 4, 22), local=True)
>>> print('Dawn:    %s' % str(sun['dawn']))
>>> print('Sunrise: %s' % str(sun['sunrise']))
>>> print('Noon:    %s' % str(sun['noon']))
>>> print('Sunset:  %s' % str(sun['sunset']))
>>> print('Dusk:    %s' % str(sun['dusk']))
Dawn:     2009-04-22 05:12:56+01:00
Sunrise:  2009-04-22 05:49:36+01:00
Noon:     2009-04-22 12:58:48+01:00
Sunset:   2009-04-22 20:09:07+01:00
Dusk:     2009-04-22 20:45:52+01:00

Access to the database of cities can be made through the Astral class:

>>> a = Astral()
>>> db = a.citydb
>>> london = db['London']

Timezone groups such as Europe can be accessed via attributes on the database:

>>> a = Astral()
>>> db = a.citydb
>>> europe = db.europe.cities
>>> europe.sort()
>>> europe
['Aberdeen', 'Amsterdam', 'Andorra la Vella', 'Ankara', 'Athens', ...

License

This module is licensed under the terms of the Apache V2.0 license.

Dependencies

Astral has one external dependency on ‘pytz’ which can either be obtained from Sourceforge page or via the easy_install method, whichever is your particular poison.

Installation

When you’ve added the pytz package to install astral unzip the archive to a handy location and execute the standard Python installation method:

python setup.py install

Cities

The module includes location and time zone data for the following cities. The list includes all capital cities plus some from the UK. The list also includes the US state capitals and some other US cities.

Aberdeen, Abu Dhabi, Abuja, Accra, Addis Ababa, Adelaide, Al Jubail, Algiers, Amman, Amsterdam, Andorra la Vella, Ankara, Antananarivo, Apia, Ashgabat, Asmara, Astana, Asuncion, Athens, Baghdad, Baku, Bamako, Bandar Seri Begawan, Bangkok, Bangui, Banjul, Basse-Terre, Basseterre, Beijing, Beirut, Belgrade, Belmopan, Berlin, Bern, Birmingham, Bishkek, Bissau, Bloemfontein, Bogota, Bolton, Bradford, Brasilia, Bratislava, Brazzaville, Bridgetown, Brisbane, Bristol, Brussels, Bucharest, Bucuresti, Budapest, Buenos Aires, Bujumbura, Cairo, Canberra, Cape Town, Caracas, Cardiff, Castries, Cayenne, Charlotte Amalie, Chisinau, Conakry, Copenhagen, Cotonou, Crawley, Dakar, Damascus, Dammam, Dhaka, Dili, Djibouti, Dodoma, Doha, Dublin, Dushanbe, Edinburgh, Fort-de-France, Freetown, Funafuti, Gaborone, George Town, Georgetown, Glasgow, Guatemala, Hanoi, Harare, Havana, Helsinki, Hobart, Honiara, Islamabad, Jakarta, Jerusalem, Jubail, Kabul, Kampala, Kathmandu, Khartoum, Kiev, Kigali, Kingston, Kingstown, Kinshasa, Koror, Kuala Lumpur, Kuwait, La Paz, Leeds, Leicester, Libreville, Lilongwe, Lima, Lisbon, Liverpool, Ljubljana, Lome, London, Luanda, Lusaka, Luxembourg, Macau, Madinah, Madrid, Makkah, Malabo, Male, Mamoudzou, Managua, Manama, Manchester, Manila, Maputo, Maseru, Masqat, Mbabane, Mecca, Medina, Mexico, Minsk, Mogadishu, Monrovia, Montevideo, Moroni, Moscow, Moskva, N’Djamena, Nairobi, Nassau, New Delhi, Newcastle, Newcastle Upon Time, Niamey, Nicosia, Norwich, Nouakchott, Noumea, Nuku’alofa, Nuuk, Oranjestad, Oslo, Ottawa, Ouagadougou, Oxford, P’yongyang, Pago Pago, Palikir, Panama, Papeete, Paramaribo, Paris, Perth, Phnom Penh, Plymouth, Port Moresby, Port-Vila, Port-au-Prince, Porto-Novo, Portsmouth, Prague, Praia, Pretoria, Quito, Reading, Reykjavik, Riga, Riyadh, Road Town, Rome, Roseau, Saint Pierre, Saipan, San Jose, San Juan, San Marino, San Salvador, Santiago, Santo Domingo, Sao Tome, Sarajevo, Seoul, Sheffield, Skopje, Sofia, Southampton, St. Peter Port, Stanley, Stockholm, Sucre, Suva, Swansea, Swindon, Sydney, T’bilisi, Tallinn, Tarawa, Tashkent, Tegucigalpa, Tehran, Thimphu, Tirane, Torshavn, Tripoli, Tunis, Vaduz, Valletta, Vienna, Vientiane, Vilnius, W. Indies, Warsaw, Washington DC, Wellington, Willemstad, Windhoek, Wolverhampton, Yamoussoukro, Yangon, Yaounde, Yerevan, Zagreb

US Cities

Albany, Albuquerque, Anchorage, Annapolis, Atlanta, Augusta, Austin, Baltimore, Baton Rouge, Billings, Birmingham, Bismarck, Boise, Boston, Bridgeport, Buffalo, Burlington, Carson City, Charleston, Charlotte, Cheyenne, Chicago, Cleveland, Columbia, Columbus, Concord, Dallas, Denver, Des Moines, Detroit, Dover, Fargo, Frankfort, Harrisburg, Hartford, Helena, Honolulu, Houston, Indianapolis, Jackson, Jacksonville, Jefferson City, Juneau, Kansas City, Lansing, Las Vegas, Lincoln, Little Rock, Los Angeles, Louisville, Madison, Manchester, Memphis, Miami, Milwaukee, Minneapolis, Montgomery, Montpelier, Nashville, New Orleans, New York, Newark, Oklahoma City, Olympia, Omaha, Orlando, Philadelphia, Phoenix, Pierre, Portland, Portland, Providence, Raleigh, Richmond, Sacramento, Saint Paul, Salem, Salt Lake City, San Diego, San Francisco, Santa Fe, Seattle, Sioux Falls, Springfield, Tallahassee, Toledo, Topeka, Trenton, Virginia Beach, Wichita, Wilmington

Thanks

The sun calculations in this module were adapted, for Python, from the following spreadsheet.

http://www.ecy.wa.gov/programs/eap/models/twilight.zip

Which takes its calculations from

http://www.srrb.noaa.gov/highlights/sunrise/azel.html

The moon phase calculation is based on some javascript code from Sky and Telescope magazine

Moon-phase calculation
Roger W. Sinnott, Sky & Telescope, June 16, 2006.

Also to Sphinx for making doc generation an easy thing (not that the writing of the docs is any easier.)

Contact

Simon Kennedy <python@sffjunkie.co.uk>

Version History

Version

Description

0.5

  • Changed City to accept unicode name and country.

  • Moved city information into a database class CityDB

  • Added attribute access to database for timezone groups

0.4

  • Duplicate city names could not be accessed.

  • Sun calculations for some cities failed with times outside valid ranges.

  • Fixes for city data.

  • Added calculation for moon phase.

0.3

  • Changed to Apache V2.0 license.

  • Fix for bug 555508 submitted by me.

  • US state capitals and other cities added.

0.2

Fix for bug 554041 submitted by Derek_ / John Dimatos

0.1

First release

Metadata

Release files for astral 0.5

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

Source distribution (sdist)

Source distribution for astral 0.5
File Size Uploaded Provenance Actions
astral-0.5.zip 173.9 kB Without provenance Details for astral-0.5.zip

Release files / astral-0.5.zip

Download URL astral-0.5.zip
Size 173.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f248a9298963a8873acefe14b334a5933d1fd9f3caee1c6a61a588cedec48d6b
BLAKE2b-256 checksum
How to use checksums
713cceb75e93cfaa4b117b2c78f14c5a94d61ca501974445f258269c08a0b431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for astral 0.5

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.

Release history Release notifications | RSS feed

This release

0.5 This release

1 release file No provenance

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