pyinfra-collector
Resources for use with pyinfra that collect facts from the whole inventory into a local store.
It's all work-in-progress, expect more resources and docs soon.
Collecting facts across the inventory
A pyinfra fact is gathered from one host at a time. Sometimes a deploy needs the values from every host on the controller side, for example to fill one template with the uptime of the whole fleet.
The pyinfra_collector.collector module gathers such values once and keeps them
in a local SQLite store, where every deployment phase can read them back.
How it works
Collection happens in two steps, because gathering is not a per-host operation:
register()records the facts to collect. It does not touch any host.- The
collect()deploy gathers everything registered, once per run, and writes it to the store.
This split means a deploy can register facts as it goes and does not need to know the full list up front. Registering the same fact twice is a no-op.
Example
from pyinfra.facts import server
from pyinfra.operations import files
from pyinfra.api.deploy import deploy
from pyinfra_collector.collector import collect, register
from pyinfra_collector.store import FactStore
@deploy()
def gather() -> None:
register(server.Uptime)
collect()
@deploy()
def publish() -> None:
with FactStore() as store:
uptimes = store.latest_for("server.Uptime")
files.template(
src="uptimes.j2",
dest="/var/cache/pyinfra-collector/uptimes",
uptimes=uptimes,
)
Run gather and publish as separate pyinfra invocations. uptimes is then a
mapping of node name to the latest collected value, ready for a template or for
looping over on the controller.
Filtering hosts
register() takes an include predicate. A host contributes only when the
predicate returns true. The predicate receives the host and the fact class, and
may inspect the host object, its groups and data, or gather another fact:
register(server.Uptime, include=lambda host, fact: "web" in host.groups)
The store
The store is an append-only log of observations, keyed by node, fact, and the arguments the fact was called with. A new row is written only when the value changes, so repeatedly collecting an unchanged fact does not grow the store.
The database lives at .pyinfra-collector.sqlite3 in the current directory. The
schema uses a TIMESTAMP column for the collection time and stores the fact
arguments and values as JSON text.
FactStore offers:
latest(node, fact, args)— the newest value for one node and fact.latest_for(fact)— a mapping of node name to newest value, for every node that ever reported the fact.history(node, fact, args)— every observation, newest first.record(...)— append one observation, skipping it if unchanged.prune(keep=..., older_than=...)— delete old observations.keepretains the newest rows per fact tuple;older_thanlimits deletion to rows older than a duration. Call this from a teardown step.
prune() with no arguments deletes everything.
Limitations
- The store is controller-local state. It is not shared between controllers and is not distributed to the nodes.
- Values are gathered at collection time and may be stale by the time they are read. Read them in a phase that runs after the values could change, or collect again.
- Hosts are gathered in parallel through pyinfra's fact pool. Usable
parallelism follows pyinfra's
PARALLELconfiguration. - Writing to the store is serial, one row at a time.
Legalese
pyinfra-collector is © 2026 martin f. krafft
pyinfra-collector@pobox.madduck.net.
It is released under the terms of the MIT Licence.
Metadata
Release files for pyinfra-collector 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyinfra_collector-0.1.0.tar.gz | 9.0 kB | With provenance | Details for pyinfra_collector-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyinfra_collector-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pyinfra_collector-0.1.0-py3-none-any.whl |
Total release size: 18.6 kB
Release files / pyinfra_collector-0.1.0.tar.gz
| Download URL | pyinfra_collector-0.1.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b0c0854b8e5278d75153d5b7ac09037fb2af14e295f926eed3901490c97615e
|
|
BLAKE2b-256 checksum How to use checksums |
78c4c35318c2f9ad957373c7e67b0b85b4c8ade0a6500d0dafbcff139d4d0bd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logRelease files / pyinfra_collector-0.1.0-py3-none-any.whl
| Download URL | pyinfra_collector-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bfb1ce3d69a37cea5740ed2d657b069490b1893324b5e7e1ff3cb72f044cbac2
|
|
BLAKE2b-256 checksum How to use checksums |
f4e30fc0c4a8653df5a59403df566034e5f24862b7f4e67825db5c4f73688bbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logSecurity for pyinfra-collector 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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyinfra_collector-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logA 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.