Internal Architecture#
FedFred is designed to be modular, extensible, and high-performance, supporting both synchronous and asynchronous interaction with the FRED® API.
This page outlines the internal class hierarchy, core mechanisms, and design principles behind FedFred.
—
Class Hierarchy Overview#
Expand Class Hierarchy
fedfred.clients.FredAPI
(synchronous core client)fedfred.clients.FredAPI.AsyncAPI
(asynchronous core client) -fedfred.clients.FredAPI.AsyncAPI.AsyncMapsAPI
(async Maps API client)fedfred.clients.FredAPI.MapsAPI
(synchronous Maps API client)
➤ Nested clients are accessible via attributes like fred.Async
, fred.Maps
, and fred.Async.Maps
.
See FedFred API Overview for a full breakdown.
—
Key Internal Mechanisms#
Enforces the FRED 120 requests/min limit using a timestamp deque. Automatically evicts old calls and blocks excess requests.
Failed API calls (timeouts/network errors) retry using tenacity. Uses exponential backoff with jitter to avoid hammering FRED.
In-memory FIFO cache stores 256 entries by default.
Works in sync and async clients. Toggle via cache_mode
.
Async clients use httpx.AsyncClient and asyncio.Lock for concurrency-safe access and rate compliance. Suitable for high-throughput pipelines.
API responses are parsed into Python classes like:
Enables static type checking, autocompletion, and safer usage.
Supports flexible backend switching via dataframe_method
:
Pandas (DataFrame)
Polars (faster)
Dask (parallel)
GeoPandas (GeoDataFrame)
Ideal for data science, GIS, and big data use cases.
—
Design Philosophy#
Principles Behind the Package
Ease of Use: Minimal boilerplate, clear method names, simple init.
Performance: Async support, FIFO caching, adaptive retries.
Flexibility: Sync + Async, backend switching, local rate enforcement.
Reliability: Typed models, parameter validation, safe defaults.
—