Registry / data / fiscalyear

fiscalyear

JSON →
library0.4.0pypypi✓ verified 86d ago

FiscalYear is a small, lightweight Python module (current version 0.4.0) that provides utilities for managing the fiscal calendar. It extends Python's built-in `datetime` and `calendar` modules, enabling users to query the fiscal year, quarter, month, and day for any given date or datetime object. The project sees releases periodically, including bug fixes, new features, and occasional breaking changes to improve functionality and maintainability.

pip install fiscalyear
INSTALL
IMPORT
SIG · FISCALYEAR
F
fiscalyear
datapythonv0.4.0
Install
1.5s avg
Import
17ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.018s · 17.8MB
glibc
py 3.103.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}")
Debug
Known issues
breakingThe methods `quarter`, `prev_quarter`, and `next_quarter` were deprecated in v0.3.0 and completely removed in v0.4.0. Using them will result in an `AttributeError`.
fix
Use `fiscal_quarter`, `prev_fiscal_quarter`, and `next_fiscal_quarter` instead.
affects: >=0.4.0
breakingPython 2 support was dropped in `fiscalyear` v0.4.0. The library now requires Python 3.6 or newer.
fix
Ensure your project runs on Python 3.6+ or downgrade `fiscalyear` to version 0.3.2 for Python 2 compatibility.
affects: >=0.4.0
breakingAs of v0.4.0, many classes and functions that previously accepted 'int-like strings' for date components (e.g., '10' for October) now strictly require `int` types. Providing strings will lead to `TypeError` or `ValueError`.
fix
Always pass integer values for year, month, and day parameters.
affects: >=0.4.0
gotchaDirect modification of `fiscalyear` global variables (e.g., `fiscalyear.START_MONTH = 7`) is discouraged and may lead to issues or be removed in future releases. It can also cause unexpected behavior in multi-threaded environments or when working with multiple fiscal calendars.
fix
Use `fiscalyear.setup_fiscal_calendar()` to globally configure the fiscal calendar or `with fiscalyear.fiscal_calendar():` context manager for temporary changes.
affects: All versions
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.
fix
Pass 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.
fix
Replace `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.
fix
Ensure `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.

Agent activity
11 hits · last 30 days
node
8
Resources
fiscalyear — pip install fiscalyear · libregistry