facterpy
Python library to provide a cached and dictionary-like interface to Puppet's facter utility.
The library uses JSON output by default (facter 3.0+) with automatic fallback to plain text parsing for maximum compatibility and performance.
Usage
>>> import facter
>>> f = facter.Facter()
>>> f["architecture"]
'x86_64'
>>> f.lookup("uptime_seconds")
195106
>>> f.lookup("uptime_seconds") # cached result
195106
>>> f.lookup("uptime_seconds", cache=False) # force refresh
195234
>>> f.get("not_a_fact", "default_value")
'default_value'
>>> f.all # get all facts as dictionary
{'architecture': 'x86_64', 'uptime_seconds': 195234, ...}
Advanced Usage
# Custom facter path
f = facter.Facter(facter_path="/usr/local/bin/facter")
# External facts directory
f = facter.Facter(external_dir="/etc/puppetlabs/facter/facts.d")
# Include Puppet facts
f = facter.Facter(puppet_facts=True)
# Disable caching
f = facter.Facter(cache_enabled=False)
# Enable legacy facts (equivalent to facter --show-legacy)
f = facter.Facter(legacy_facts=True)
f.lookup("architecture") # Works with legacy facts enabled
f["operatingsystem"] # Legacy facts appear in f.all
Install
pip install facterpy
Requirements
Required:
- Python 3.11+
factercommand-line utility (install via system packages or Puppet)
No external Python dependencies - uses only Python standard library.
Compatibility
- Python: 3.11+ (Python 2 support removed in v0.2.0, Python 3.8-3.10 support removed in v1.1.0)
- Facter: 3.0+ (JSON output), with fallback support for older versions
- Platforms: Linux, macOS, and other POSIX systems
Legacy Facts
Modern facter (4.x+) uses structured facts, so legacy top-level facts like architecture are nested under structured facts like os.architecture. To access legacy facts that were available in older facter versions:
# Modern behavior (default) - structured facts only
f = facter.Facter()
f.lookup("architecture") # Raises KeyError - not in structured output
f.all["os"]["architecture"] # Works - nested in structured facts
# Legacy behavior - includes legacy facts (like facter --show-legacy)
f = facter.Facter(legacy_facts=True)
f.lookup("architecture") # Works - legacy fact available
f["architecture"] # Works - appears in f.all output
Migration from v0.1.x
Version 1.0.0 represented a major modernization while maintaining API compatibility. This version bump reflects the significant gap since the last release (12+ years) and commitment to not breaking existing code.
- Breaking changes: Python 2 support removed, PyYAML dependency removed
- Modernization: Complete rewrite with JSON-first approach, type hints, modern tooling
- API stability: Core API unchanged to preserve compatibility with existing code
Migration notes:
# Old (deprecated, shows warning)
f = facter.Facter(use_yaml=False)
# New (recommended)
f = facter.Facter() # Automatically uses JSON with text fallback
# For legacy fact compatibility (if needed)
f = facter.Facter(legacy_facts=True) # Includes pre-4.x style facts
Changes in v1.1.0
- Dropped Python 3.8-3.10 (all end-of-life); the minimum is now Python 3.11
- Added a
timeoutparameter (default 30 seconds) toFacter(). A hungfacterprocess now raisessubprocess.TimeoutExpiredinstead of blocking forever - Tooling modernization: ruff-format replaces black, coverage no longer forced on every test run
Project State
I wrote this library in 2013 and did very little maintenance since then, despite some apparent usage. The library is simple and focused, which has helped it remain functional. This 1.0.0 modernization brings it up to current standards while preserving the original API. I haven't used Puppet in quite some time, so I'm not an active user of this library, but the comprehensive test suite should help ensure reliability.
Release files for facterpy 1.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 | |
|---|---|---|---|
| facterpy-1.1.0.tar.gz | 10.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| facterpy-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.0 kB
Release files / facterpy-1.1.0.tar.gz
| Download URL | facterpy-1.1.0.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a1d92650db876b474ebe8b0ae928b0bd4750c97a43af1f84f11e4651d85a80b
|
|
BLAKE2b-256 checksum How to use checksums |
62a95185b816b832fa099f7fb398da52576d437413e58a7b933ae8df99689d18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 10, 2026.
Transparency logRelease files / facterpy-1.1.0-py3-none-any.whl
| Download URL | facterpy-1.1.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b44ab229ed71cd679877fa667e9a128ab9a92db0c3af6c21031d0bfbf6501a4
|
|
BLAKE2b-256 checksum How to use checksums |
676ee9b4db04201cb48c8a237d7b288c144a5eba2c210fb55d3f80201f8159ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 10, 2026.
Transparency log