call_report.fca.transport.PackagedArchiveTransport#

class call_report.fca.transport.PackagedArchiveTransport(*, archive_root: ~pathlib.Path = <factory>, dirname_for: ~collections.abc.Callable[[~call_report.core._periods.ReportingPeriod], str] = <function _default_dirname>)[source]#

Bases: object

A transport that resolves periods to the release zips shipped in data/.

By default, resolves against this repository’s own data/fca-call-report/ archive, which holds one zip per period named after FCA’s own download filename (e.g. "2026March.zip"). A checkout of this repository therefore has ready-to-use historical data with no network access required. Each zip is extracted, once per period, into a private temporary directory.

That extraction directory is a real resource, so prefer using the transport as a context manager, which removes it on exit:

with PackagedArchiveTransport() as transport:
    report = FCACallReport(start=..., end=..., transport=transport)

close does the same thing for callers that cannot use a with block, and is safe to call more than once. A transport that is never closed still cleans up when it is garbage collected, but only at whatever moment the interpreter happens to collect it, which emits a ResourceWarning under -W error.

That archive is not included in the distributed wheel (see pyproject.toml’s [tool.hatch.build.targets.wheel]), so this transport is only useful when running from a source checkout. From a pip-installed package, either pass archive_root pointing at your own directory of FCA release zips, or use LocalDirectoryTransport with already-extracted releases instead.

Attributes:
archive_rootpathlib.Path

The directory containing one <dirname>.zip per period. Defaults to this repository’s checked-in data/fca-call-report/ archive.

dirname_forCallable[[ReportingPeriod], str]

Return the default per-period directory name: the FCA zip’s stem.

Examples

>>> with PackagedArchiveTransport() as transport:
...     resolved = transport.resolve(
...         period=ReportingPeriod.from_period_end(value="2026-03-31")
...     )
...     resolved.name
'2026March'
dirname_for() str[source]#

Return the default per-period directory name: the FCA zip’s stem.

Matches the name produced by downloading and unzipping FCA’s own archive for that period.

Parameters:
periodReportingPeriod

The period to name a directory for.

Returns:
str

The FCA download URL’s filename without its .zip extension, e.g. "2026March" or "Mar2003".

resolve(*, period: ReportingPeriod) Path[source]#

Return period’s extracted files, extracting its zip on first use.

Implements the FCATransport protocol for the packaged archive.

Parameters:
periodReportingPeriod

The period to resolve.

Returns:
pathlib.Path

The directory period’s zip was extracted into.

Raises:
DownloadError

If no zip exists at the expected location under archive_root.

close() None[source]#

Remove the temporary directory this transport extracted zips into.

Safe to call more than once, and safe to call on a transport that never resolved anything, since neither creates an extraction directory to remove. After close, a further resolve call extracts into a fresh directory rather than failing, so a closed transport stays usable.

Examples

>>> transport = PackagedArchiveTransport()
>>> resolved = transport.resolve(
...     period=ReportingPeriod.from_period_end(value="2026-03-31")
... )
>>> resolved.is_dir()
True
>>> transport.close()
>>> resolved.is_dir()
False