Skip to main content

injected-time

One source of the time of the world per process: wall time, or an injected instant that a test sets and moves forward. A process reads every instant it stores, signs, sends to another party, or compares with an instant another party knows from the one source its composition root installs, and from no other read. Several processes set to one injected instant then agree on the time exactly, and a test reaches any later instant by setting it, never by waiting for it.

The component depends on the standard library alone, Python 3.10 or later. This README is its interface: the value, the sources, the time file, and the route service a process's HTTP binding wraps.

The time value

An instant is a JSON integer of Unix seconds from 0 to 253402300799, the last second of the year 9999. A document carrying one is exactly {"now": <instant>}. A boolean, a float (even 1794821400.0), a string, an instant out of range, a missing now, any other member, a member stated twice, or a body that is not JSON is refused as invalid_time (InvalidTime). Every reader applies this one rule: parse_time(raw) for a JSON body, read_time(document) for a parsed one, and check_instant(value) for a bare value.

Sources

Source name now()
WallTime(wall=time.time) wall the wall clock, in whole seconds
InjectedTime(start=None, wall=time.time) injected the instant last set; it starts at start, or at the wall instant it was made, and reads the wall clock never again
TimeFile(path) injected the instant the file holds, read on every call

InjectedTime.set(instant) moves the source to instant. An instant earlier than the current one is refused as time_moves_forward (TimeMovesForward, carrying both instants), an invalid one as invalid_time, and neither changes anything; setting the current instant again succeeds. wall, a function reading the wall clock in seconds, is how a test stands in for the wall clock.

A process installs its source once, at its composition root, from its configuration's source value, and reads it through the module-level now():

import injected_time

injected_time.install(injected_time.source_for(settings.time_source, setting="time.source"))
...
stamped_at = injected_time.now()

source_for accepts exactly "wall" and "injected"; any other value is refused (InvalidTimeSource), naming the setting and the value. Until a root installs a source, now() reads wall time. now_datetime() is the same instant as an aware UTC datetime, its microsecond 0. A function that takes a clock keeps it injectable by defaulting it to injected_time.now.

A duration of the process's own activity — a timeout, a poll budget, a backoff, an interval — is not the time of the world. Measure it on time.monotonic(), which neither stops while injected time is held nor jumps when it is set.

The time file

A process with no route of its own to set its time — a command-line tool started afresh for each step, say — reads its injected time from a time file holding the time document. TimeFile(path).now() reads the file on every call, so a running process sees a later instant at its next read; a missing, unreadable or invalid file raises TimeFileError naming the file, and there is no fallback to wall time. TimeFile(path).write(instant) replaces the file whole: it writes a complete file in the same directory and renames it over the old one, so a reader sees the previous document or the new one, never part of either.

The route service

TimeRouteService(source) is framework-free. A service binds it behind its own administrator authentication, at a path of its own:

  • status() is the status section: {"source": "injected", "now": <instant>}, or {"source": "wall"}.
  • set_time(body) reads the raw request body by the value rule, sets the source, and answers {"source": "injected", "now": <instant>}. It refuses with TimeRouteError carrying status_code, code and detail: 422 invalid_time for a body the rule refuses, 409 time_moves_forward for an earlier instant; neither changes anything.
  • settable is true only for an InjectedTime source. A service binds the setting route only then, so an instance on wall time offers no way to change its time.

Development

From this directory:

  • make test type-checks the package and runs its unit tests, the structure test holding its boundary among them.
  • make build builds its wheel into dist/, or into DIST_DIR.

Metadata

Release files for arkhai-injected-time 0.1.0

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

Built distribution (wheel)

Table of built distributions (wheels) for arkhai-injected-time 0.1.0
File Interpreter ABI Platform Actions
arkhai_injected_time-0.1.0-py3-none-any.whl Python 3 none any Details for arkhai_injected_time-0.1.0-py3-none-any.whl

Release files / arkhai_injected_time-0.1.0-py3-none-any.whl

Download URL arkhai_injected_time-0.1.0-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb110a97f2352f4746cba0c481bc668a37d7a7d14469ccbe015702090f75172d
BLAKE2b-256 checksum
How to use checksums
3b1a23510936887841849ad3d92b08e8f6e9eca2e8f06d21d259bc904390e173
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for arkhai-injected-time 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

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