ArcticDB-backed time series cache with incremental updates — fetch once, upsert the gap.
Project description
arctic-incr-cache
ArcticDB-backed time series cache with incremental updates.
First call fetches the full window from your data source and stores it in ArcticDB. Subsequent calls only fetch the gap between the cached tail and the requested end — then merge and upsert. Incomplete (still-updating) bars are automatically excluded from storage so they never overwrite finalised data.
Install
pip install arctic-incr-cache
# or
uv add arctic-incr-cache
Quick start
import datetime
import arcticdb as adb
from zoneinfo import ZoneInfo
from arctic_incr_cache import IncrCache
arctic = adb.Arctic("lmdb://data/arcticdb")
lib = arctic.get_library("ohlcv-1d", create_if_missing=True)
cache = IncrCache(
lib,
fetch=lambda symbol, end, count: your_api.get_daily_bars(symbol, end=end, count=count),
get_tz=lambda symbol: ZoneInfo("America/New_York"),
)
df = cache.get("AAPL", end=datetime.date(2024, 6, 1), count=60)
- First call — fetches 60 bars from your API, stores in ArcticDB, returns.
- Second call (same or later end) — serves from ArcticDB; fetches only the gap if the cache is stale.
Intraday data
Set bar_minutes to the bar width and provide get_tz to return the market
timezone:
from zoneinfo import ZoneInfo
intraday = IncrCache(
lib,
fetch=lambda symbol, end, count: your_api.get_minute_bars(symbol, end=end, count=count),
bar_minutes=1,
default_count=390 * 5,
get_tz=lambda symbol: ZoneInfo("America/New_York"),
)
Concurrency
By default writes run in a daemon thread. Pass spawn and lock_class for
gevent or other async runtimes:
import gevent
import gevent.lock
cache = IncrCache(
lib,
fetch=my_fetch,
spawn=gevent.spawn,
lock_class=gevent.lock.BoundedSemaphore,
)
Timezone handling
When get_tz returns a timezone for a symbol:
fetchreturn — must be tz-aware. Timestamps are converted to the configured market timezone internally.- Storage — data is stored in ArcticDB as tz-aware in the configured timezone.
- Return —
get()returns a tz-aware DataFrame in the configured timezone. endparameter —datebecomes end-of-day in market timezone; naivedatetimeis interpreted as local timezone, then converted; tz-aware is converted directly.
Interval convention
- Data & return — both ends inclusive (
index <= end). The returned DataFrame includes the bar atendif it exists. - Freshness check — left-closed right-open. The cache considers data fresh when the last cached bar reaches
end - bar_width, since the bar atenditself may not yet exist.
Constructor parameters
| Parameter | Required | Description |
|---|---|---|
library |
yes | ArcticDB library instance |
fetch(symbol, end, count) |
yes | Fetch raw data from upstream; must return tz-aware timestamps |
get_tz(symbol) |
yes | Market timezone (tzinfo) for each symbol |
bar_minutes |
no | Bar width in minutes (default 1440 = daily) |
default_count |
no | Bars returned when count is omitted (default 252) |
spawn |
no | Fire-and-forget callable for async writes (default: daemon thread) |
lock_class |
no | Lock constructor (default: threading.Lock) |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arctic_incr_cache-0.1.7.tar.gz.
File metadata
- Download URL: arctic_incr_cache-0.1.7.tar.gz
- Upload date:
- Size: 46.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2ad19a2d01d6ae403af4833bfe8ba6396a326abffa4a93f9b3c25e5eee4e2e2
|
|
| MD5 |
1fa255f8ad806fce9ebdc36ef8ac100b
|
|
| BLAKE2b-256 |
5d60def0d1c1eed9cbbef7a55236b9f601ed57ac93f41a04e6241a6d50ce749a
|
File details
Details for the file arctic_incr_cache-0.1.7-py3-none-any.whl.
File metadata
- Download URL: arctic_incr_cache-0.1.7-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6500bc99a330b701e4183a6b9efefe3c6d113c3920520ca090494e4f084f49a0
|
|
| MD5 |
71c5bb9dc31c6e54c264b489b441dece
|
|
| BLAKE2b-256 |
d08e51828bea795316934a02d59d7d6509a0a0071f1ea1bc432f20071b9ec790
|