python-holidays
A fast, efficient Python library for generating country- and subdivision- (e.g. state or province) specific sets of government-designated holidays on the fly. It aims to make determining whether a specific date is a holiday as fast and flexible as possible.
Package: | |
---|---|
CD/CI: | |
Docs: | |
Meta: |
Install
The latest stable version can always be installed or updated via pip:
$ pip install --upgrade holidays
Documentation
The documentation is hosted on Read the Docs.
Quick Start
from datetime import date
import holidays
us_holidays = holidays.US() # this is a dict
# the below is the same, but takes a string:
us_holidays = holidays.country_holidays('US') # this is a dict
nyse_holidays = holidays.NYSE() # this is a dict
# the below is the same, but takes a string:
nyse_holidays = holidays.financial_holidays('NYSE') # this is a dict
date(2015, 1, 1) in us_holidays # True
date(2015, 1, 2) in us_holidays # False
us_holidays.get('2014-01-01') # "New Year's Day"
The HolidayBase dict-like class will also recognize date strings and Unix timestamps:
'2014-01-01' in us_holidays # True
'1/1/2014' in us_holidays # True
1388597445 in us_holidays # True
Some holidays may be only present in parts of a country:
us_pr_holidays = holidays.country_holidays('US', subdiv='PR')
'2018-01-06' in us_holidays # False
'2018-01-06' in us_pr_holidays # True
Please see the python-holidays documentation for additional examples and detailed information.
Available Countries
We currently support 131 country codes. The standard way to refer to a country
is by using its ISO 3166-1 alpha-2 code, the same used for domain names, and
for a subdivision its ISO 3166-2 code. Some of the countries support more
than one language for holiday names output.
A default language is defined by default_language
(optional) attribute
for each entity and is used as a fallback when neither user specified
language nor user locale language available. The default language code is
a ISO 639-1 code. A list of all languages supported by country is defined by
supported_languages
(optional) attribute. If there is no designated
ISO 639-1 code then ISO 639-2 code can be used.
The list of supported countries, their subdivisions and supported languages (all default values are hightlighted with bold):
Country | Code | Subdivisions | Supported Languages |
---|---|---|---|
Albania | AL | Â | Â |
Algeria | DZ | Â | ar, en_US |
American Samoa | AS | Can also be loaded as country US, subdivision AS | Â |
Andorra | AD | Parishes: 02, 03, 04, 05, 06, 07, 08 | Â |
Angola | AO | Â | en_US, pt_AO, uk |
Argentina | AR | Â | en_US, es, uk |
Armenia | AM | Â | en_US, hy |
Aruba | AW | Â | en_US, nl, pap, uk |
Australia | AU | States and territories: ACT, NSW, NT, QLD, SA, TAS, VIC, WA | Â |
Austria | AT | States: 1, 2, 3, 4, 5, 6, 7, 8, 9 | de, en_US, uk |
Azerbaijan | AZ | Â | Â |
Bahrain | BH | Â | ar, en_US |
Bangladesh | BD | Â | Â |
Belarus | BY | Â | be, en_US |
Belgium | BE | Â | de, en_US, fr, nl, uk |
Belize | BZ | Â | Â |
Bolivia | BO | Departments: B, C, H, L, N, O, P, S, T | en_US, es, uk |
Bosnia and Herzegovina | BA | Entities and district: BIH, BRC, SRP | bs, en_US, sr, uk |
Botswana | BW | Â | Â |
Brazil | BR | States: AC, AL, AM, AP, BA, CE, DF, ES, GO, MA, MG, MS, MT, PA, PB, PE, PI, PR, RJ, RN, RO, RR, RS, SC, SE, SP, TO | Â |
Brunei | BN | Â | en_US, ms, th |
Bulgaria | BG | Â | bg, en_US, uk |
Burkina Faso | BF | Â | Â |
Burundi | BI | Â | Â |
Cambodia | KH | Â | en_US, km, th |
Cameroon | CM | Â | Â |
Canada | CA | Provinces and territories: AB, BC, MB, NB, NL, NS, NT, NU, ON, PE, QC, SK, YT | ar, en, en_US, fr, th |
Chad | TD | Â | Â |
Chile | CL | Regions: AI, AN, AP, AR, AT, BI, CO, LI, LL, LR, MA, ML, NB, RM, TA, VS | en_US, es, uk |
China | CN | Â | Â |
Colombia | CO | Â | en_US, es, uk |
Costa Rica | CR | Â | en_US, es, uk |
Croatia | HR | Â | en_US, hr, uk |
Cuba | CU | Â | en_US, es, uk |
Curacao | CW | Â | en_US, nl, pap, uk |
Cyprus | CY | Â | el, en_US |
Czechia | CZ | Â | cs, en_US, uk |
Denmark | DK | Â | da, en_US, uk |
Djibouti | DJ | Â | ar, en_US, fr |
Dominican Republic | DO | Â | en_US, es, uk |
Ecuador | EC | Â | en_US, es, uk |
Egypt | EG | Â | ar, en_US |
El Salvador | SV | Departments: AH, CA, CH, CU, LI, MO, PA, SA, SM, SO, SS, SV, UN, US | Â |
Estonia | EE | Â | en_US, et, uk |
Eswatini | SZ | Â | Â |
Ethiopia | ET | Â | am, ar, en_US |
Finland | FI | Â | en_US, fi, sv, uk |
France | FR | Départements: BL, GES, GP, GY, MF, MQ, NC, PF, RE, WF, YT | en_US, fr, uk |
Gabon | GA | Â | Â |
Georgia | GE | Â | en_US, ka, uk |
Germany | DE | States: BB, BE, BW, BY, BYP, HB, HE, HH, MV, NI, NW, RP, SH, SL, SN, ST, TH | de, en_US, uk |
Greece | GR | Â | el, en_US, uk |
Guam | GU | Can also be loaded as country US, subdivision GU | Â |
Guatemala | GT | Â | en_US, es |
Honduras | HN | Â | en_US, es, uk |
Hong Kong | HK | Â | Â |
Hungary | HU | Â | en_US, hu, uk |
Iceland | IS | Â | en_US, is, uk |
India | IN | States: AN, AP, AR, AS, BR, CG, CH, DD, DH, DL, GA, GJ, HP, HR, JH, JK, KA, KL, LA, LD, MH, ML, MN, MP, MZ, NL, OR, PB, PY, RJ, SK, TN, TR, TS, UK, UP, WB | Â |
Indonesia | ID | Â | en_US, id, uk |
Ireland | IE | Â | Â |
Isle of Man | IM | Â | Â |
Israel | IL | Â | Â |
Italy | IT | Provinces: AG, AL, AN, AO, AP, AQ, AR, AT, AV, BA, BG, BI, BL, BN, BO, BR, BS, BT, BZ, CA, CB, CE, CH, CL, CN, CO, CR, CS, CT, CZ, EN, FC, FE, FG, FI, FM, FR, GE, GO, GR, IM, IS, KR, LC, LE, LI, LO, LT, LU, MB, MC, ME, MI, MN, MO, MS, MT, NA, NO, NU, OR, PA, PC, PD, PE, PG, PI, PN, PO, PR, PT, PU, PV, PZ, RA, RC, RE, RG, RI, RM, RN, RO, SA, SI, SO, SP, SR, SS, SU, SV, TA, TE, TN, TO, TP, TR, TS, TV, UD, VA, VB, VC, VE, VI, VR, VT, VV. Cities: Andria, Barletta, Cesena, Forli, Pesaro, Trani, Urbino | Â |
Jamaica | JM | Â | Â |
Japan | JP | Â | en_US, ja |
Kazakhstan | KZ | Â | Â |
Kenya | KE | Â | Â |
Kyrgyzstan | KG | Â | Â |
Latvia | LV | Â | en_US, lv, uk |
Lesotho | LS | Â | Â |
Liechtenstein | LI | Â | de, en_US, uk |
Lithuania | LT | Â | en_US, lt, uk |
Luxembourg | LU | Â | de, en_US, fr, lb, uk |
Madagascar | MG | Â | en_US, mg, uk |
Malawi | MW | Â | Â |
Malaysia | MY | States: JHR, KDH, KTN, KUL, LBN, MLK, NSN, PHG, PJY, PLS, PNG, PRK, SBH, SGR, SWK, TRG | Â |
Malta | MT | Â | en_MT, mt |
Marshall Islands (the) | MH | Â | Â |
Mexico | MX | Â | en_US, es, uk |
Moldova | MD | Â | en_US, ro, uk |
Monaco | MC | Â | en_US, fr, uk |
Montenegro | ME | Â | Â |
Morocco | MA | Â | ar, en_US, fr |
Mozambique | MZ | Â | en_US, pt_MZ, uk |
Namibia | NA | Â | Â |
Netherlands | NL | Â | en_US, nl, uk |
New Zealand | NZ | Regions: AUK, BOP, CAN, CIT, GIS, HKB, MBH, MWT, NSN, NTL, OTA, STL, TAS, TKI, WGN, WKO, WTC | Â |
Nicaragua | NI | Departments: AN, AS, BO, CA, CI, CO, ES, GR, JI, LE, MD, MN, MS, MT, NS, RI, SJ | en_US, es, uk |
Nigeria | NG | Â | Â |
Northern Mariana Islands (the) | MP | Can also be loaded as country US, subdivision MP | Â |
North Macedonia | MK | Â | Â |
Norway | NO | Â | en_US, no, uk |
Pakistan | PK | Â | Â |
Panama | PA | Â | Â |
Paraguay | PY | Â | en_US, es, uk |
Peru | PE | Â | en_US, es, uk |
Philippines | PH | Â | Â |
Poland | PL | Â | en_US, pl, uk |
Portugal | PT | Districts: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 30, Ext; Use subdiv='Ext' to include holidays most people have off | en_US, pt_PT |
Puerto Rico | PR | Can also be loaded as country US, subdivision PR | Â |
Romania | RO | Â | en_US, ro, uk |
Russia | RU | Â | en_US, ru |
San Marino | SM | Â | Â |
Saudi Arabia | SA | Â | ar, en_US |
Serbia | RS | Â | en_US, sr |
Singapore | SG | Â | Â |
Slovakia | SK | Â | en_US, sk, uk |
Slovenia | SI | Â | en_US, sl, uk |
South Africa | ZA | Â | Â |
South Korea | KR | Â | Â |
Spain | ES | Autonomous communities: AN, AR, AS, CB, CE, CL, CM, CN, CT, EX, GA, IB, MC, MD, ML, NC, PV, RI, VC | Â |
Sweden | SE | Â | en_US, sv, uk |
Switzerland | CH | Cantons: AG, AR, AI, BL, BS, BE, FR, GE, GL, GR, JU, LU, NE, NW, OW, SG, SH, SZ, SO, TG, TI, UR, VD, VS, ZG, ZH | de, en_US, fr, it, uk |
Taiwan | TW | Â | Â |
Thailand | TH | Â | en_US, th |
Tunisia | TN | Â | ar, en_US |
Turkey | TR | Â | Â |
Ukraine | UA | Â | ar, en_US, uk |
United Arab Emirates | AE | Â | ar, en_US |
United Kingdom | GB | Subdivisions: ENG, NIR, SCT, WLS | Â |
United States Minor Outlying Islands | UM | Can also be loaded as country US, subdivision UM | Â |
United States of America (the) | US | States and territories: AK, AL, AR, AS, AZ, CA, CO, CT, DC, DE, FL, FM, GA, GU, HI, IA, ID, IL, IN, KS, KY, LA, MA, MD, ME, MH, MI, MN, MO, MP, MS, MT, NC, ND, NE, NH, NJ, NM, NV, NY, OH, OK, OR, PA, PR, PW, RI, SC, SD, TN, TX, UM, UT, VA, VI, VT, WA, WI, WV, WY | Â |
United States Virgin Islands (the) | Â | See Virgin Islands (U.S.) | Â |
Uruguay | UY | Â | en_US, es, uk |
Uzbekistan | UZ | Â | Â |
Vatican City | VA | Â | Â |
Venezuela | VE | Â | en_US, es, uk |
Vietnam | VN | Â | Â |
Virgin Islands (U.S.) | VI | Can also be loaded as country US, subdivision VI | Â |
Zambia | ZM | Â | Â |
Zimbabwe | ZW | Â | Â |
Available Financial Markets
The standard way to refer to a financial market is to use its ISO 10383 MIC (Market Identifier Code) as a "country" code when available. The following financial markets are available:
Entity | Code | Info |
---|---|---|
European Central Bank | ECB | Trans-European Automated Real-time Gross Settlement (TARGET2) |
New York Stock Exchange | XNYS | NYSE market holidays (used by all other US-exchanges, including NASDAQ, etc.) |
Beta Version
The latest development (beta) version can be installed directly from GitHub:
$ pip install --upgrade https://github.com/vacanza/python-holidays/tarball/beta
All new features are always first pushed to beta branch, then released on master branch upon official version upgrades.
Contributions
Issues and pull requests are always welcome. Please see here for more information.
License
Code and documentation are available according to the MIT License (see LICENSE).