Skip to main content

refresh-engine

PyPI Python CI Documentation License

Keep anything in sync with its source by refreshing only what changed.

refresh-engine is an asyncio-first, domain-neutral Python library for keeping derived data current: search indexes, caches, embeddings, configuration, registries, or anything else built from a source. You describe how to list and read resources and how to apply a change; the engine detects what changed, plans the work in dependency order, runs it safely, and remembers the outcome.

Discover, observe, detect changes, plan, execute, and persist

Features

  • Precise change detection. Deterministic fingerprints detect added, modified, and deleted resources. Reliable cheap indicators, such as ETags or version tokens, skip reading unchanged resources entirely.
  • Four refresh modes. Incremental, full, dependency-aware, and targeted refreshes, with targets chosen by ID or by composable selectors.
  • Dependency ordering. Dependencies are refreshed before their dependents, changes propagate to everything that depends on them, and cycles are isolated.
  • Safe by default. Bounded concurrency, retries with jittered exponential backoff, timeouts, and fail-fast or best-effort policies. A partial discovery never deletes anything, and failed work is retried by the next refresh.
  • Durable state. State advances only for successful resources, in one atomic commit per refresh. Use the in-memory store or plug in your own database.
  • Scheduling and overlap control. A drift-free interval scheduler and policies that coalesce, queue, skip, or supersede overlapping requests.
  • Observability. Typed lifecycle events with correlation IDs, structured logging through structlog with secret redaction, metrics, and optional OpenTelemetry spans and metrics using application-owned providers.
  • Lightweight and typed. Fully type-annotated, with two runtime dependencies: structlog and tenacity.

Installation

refresh-engine requires Python 3.12 or newer.

pip install refresh-engine

For the optional OpenTelemetry integration, install refresh-engine[otel]. The extra adds the OpenTelemetry API; your application provides the SDK and exporters.

Quick start

Implement a source that lists and reads resources, and an operation that applies each change. The engine does the rest:

import asyncio

from refresh_engine import (
    DiscoveryResult,
    PlanAction,
    RefreshEngine,
    RefreshEngineConfig,
    RefreshRequest,
    Resource,
    ResourceSnapshot,
    ResourceSource,
)

CATALOG = {"apples": 120, "pears": 80}
SEARCH_INDEX: dict[str, int] = {}


class InventorySource(ResourceSource):
    async def discover(self) -> DiscoveryResult:
        return DiscoveryResult(Resource(item) for item in sorted(CATALOG))

    async def snapshot(self, resource: Resource, /) -> ResourceSnapshot:
        return ResourceSnapshot(
            resource.resource_id, content=CATALOG[resource.resource_id]
        )


async def update_index(
    resource: Resource,
    snapshot: ResourceSnapshot | None,
    action: PlanAction,
    request: RefreshRequest,
    /,
) -> None:
    if action is PlanAction.DELETE:
        SEARCH_INDEX.pop(resource.resource_id, None)
    elif snapshot is not None:
        SEARCH_INDEX[resource.resource_id] = snapshot.content


async def main() -> None:
    async with RefreshEngine(
        RefreshEngineConfig(source=InventorySource(), operation=update_index)
    ) as engine:
        first = await engine.refresh(RefreshRequest())
        print(f"{first.status}: refreshed {first.refreshed_count}", SEARCH_INDEX)

        CATALOG["pears"] = 75
        del CATALOG["apples"]
        second = await engine.refresh(RefreshRequest())
        print(
            f"{second.status}: modified {second.modified_count},"
            f" deleted {second.deleted_count}",
            SEARCH_INDEX,
        )


asyncio.run(main())
success: refreshed 2 {'apples': 120, 'pears': 80}
success: modified 1, deleted 1 {'pears': 75}

The second refresh touches only the modified and the deleted resource. Continue with the getting started guide to add durable state, dependencies, scheduling, and logging.

Performance

The engine's overhead is small next to real I/O: with in-memory sources, a full refresh of 100,000 resources takes about 3 seconds, and an incremental refresh that finds nothing changed takes about half a second. See the benchmarks for the method and details.

Downloads

Total downloads Downloads this week Downloads this month Downloads this year

Downloads by year Downloads by country: A Downloads by country: B Downloads by country: C Downloads by country: D Downloads by country: E Downloads by country: F Downloads by country: G Downloads by country: H Downloads by country: I Downloads by country: J Downloads by country: K Downloads by country: L Downloads by country: M Downloads by country: N-O Downloads by country: P Downloads by country: R Downloads by country: S Downloads by country: T Downloads by country: U-Y

Counts come from the ClickHouse public PyPI dataset, which refreshes daily, so they may be about a day behind. Shields caches badge images for up to an hour, and GitHub may cache them longer. Weeks start on Monday in UTC. Explore interactive charts on the ClickPy dashboard.

Documentation

The documentation covers:

Agent Skills

Coding agents such as Claude Code, Codex, Cursor, and GitHub Copilot can use the refresh-engine Agent Skill to integrate the library correctly:

npx skills add https://github.com/smuniharish/refresh-engine/tree/master/refresh-engine-skills/skills/refresh-engine

Contributing

Contributions are welcome. Read the contributing guide, and report vulnerabilities as described in the security policy. Notable changes are listed in the changelog.

License

refresh-engine is licensed under the Apache License 2.0.

Metadata

Release files for refresh-engine 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for refresh-engine 2.0.0
File Size Uploaded Provenance Actions
refresh_engine-2.0.0.tar.gz 68.2 kB Without provenance Details for refresh_engine-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for refresh-engine 2.0.0
File Interpreter ABI Platform Actions
refresh_engine-2.0.0-py3-none-any.whl Python 3 none any Details for refresh_engine-2.0.0-py3-none-any.whl

Total release size: 143.1 kB

Release files / refresh_engine-2.0.0.tar.gz

Download URL refresh_engine-2.0.0.tar.gz
Size 68.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7d4d284111447909d4574a69ca1003b0381b97d9d4ce2e1c784cbc03e8e4ee8a
BLAKE2b-256 checksum
How to use checksums
d0632859f6ba9c51e4118d8ea40833a41520397054082a7ea589e14df79bcfc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / refresh_engine-2.0.0-py3-none-any.whl

Download URL refresh_engine-2.0.0-py3-none-any.whl
Size 74.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb2aacd8dc7278c7f0f16679f6498b7f91777c96913df8235347b6b94031e1d2
BLAKE2b-256 checksum
How to use checksums
59b7819eada84568bd43f672d0f4087b44c9bcaa546f6cf4385284d18651cea6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for refresh-engine 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page