Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.018s · 17.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.017s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
FiscalYear
✓ from fiscalyear import FiscalYear
FiscalQuarter
✓ from fiscalyear import FiscalQuarter
FiscalMonth
✓ from fiscalyear import FiscalMonth
FiscalDay
✓ from fiscalyear import FiscalDay
FiscalDate
✓ from fiscalyear import FiscalDate
setup_fiscal_calendar
✓ from fiscalyear import setup_fiscal_calendar
fiscal_calendar
✓ from fiscalyear import fiscal_calendar
This quickstart demonstrates how to initialize `fiscalyear`, globally set a custom fiscal year start month using `setup_fiscal_calendar`, and retrieve fiscal information for specific dates. It also shows the use of the `fiscal_calendar` context manager for temporary fiscal calendar adjustments without affecting global settings.
import datetime
from fiscalyear import FiscalYear, FiscalDate, setup_fiscal_calendar, fiscal_calendar
# Set fiscal year to start in July globally
setup_fiscal_calendar(start_month=7)
# Get current fiscal year information
current_fy = FiscalYear.current()
print(f"Current Fiscal Year: {current_fy.year}")
print(f"FY Start: {current_fy.start.date()}, FY End: {current_fy.end.date()}")
# Get fiscal info for a specific date
some_date = datetime.date(2024, 11, 15)
f_date = FiscalDate(some_date.year, some_date.month, some_date.day)
print(f"\nDate: {f_date}")
print(f"Fiscal Year: {f_date.fiscal_year}")
print(f"Fiscal Quarter: {f_date.fiscal_quarter}")
print(f"Fiscal Month: {f_date.fiscal_month}")
# Temporarily change fiscal calendar using context manager
with fiscal_calendar(start_month=4):
temp_f_date = FiscalDate(2024, 11, 15)
print(f"\nInside context manager (April start) for {temp_f_date}:")
print(f"Temporary Fiscal Year: {temp_f_date.fiscal_year}")
print(f"Temporary Fiscal Quarter: {temp_f_date.fiscal_quarter}")
# Outside context manager, global setting (July start) is restored
print(f"\nOutside context manager: Fiscal Year for {f_date}: {f_date.fiscal_year}")
Errors
Common errors & fixes
TypeError: FiscalDate() takes 3 positional arguments but 4 were given
Attempting to pass a `datetime.datetime` or `datetime.date` object directly to `FiscalDate()` instead of its constituent year, month, and day components.
fixPass the year, month, and day as separate integer arguments: `FiscalDate(my_datetime_obj.year, my_datetime_obj.month, my_datetime_obj.day)`.
AttributeError: module 'fiscalyear' has no attribute 'quarter'
Using the deprecated `quarter` attribute or method, which was removed in version 0.4.0.
fixReplace `object.quarter` with `object.fiscal_quarter`. For previous/next, use `prev_fiscal_quarter` and `next_fiscal_quarter`.
The fiscalyear.setup_fiscal_calendar(start_month=X) does not correctly apply the start month, resulting in incorrect fiscal year/quarter calculations.
While a specific bug related to `fiscal_month` and `START_DAY` was fixed in v0.3.2, user reports indicate ongoing issues or confusion with `setup_fiscal_calendar`'s application, potentially due to incorrect usage or interaction with other settings.
fixEnsure `setup_fiscal_calendar` is called early in your application's lifecycle, preferably before any `FiscalYear` or `FiscalDate` objects are instantiated. Double-check the `start_year`, `start_month`, and `start_day` parameters. For temporary changes, use the `fiscal_calendar` context manager.
Upgrade
Version history
0.4.0latest on PyPI · released Feb 17, 2022
Audit
Dependencies
No dependency data recorded yet.