Skip to main content

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.8+
  • facter command-line utility (install via system packages or Puppet)

No external Python dependencies - uses only Python standard library.

Compatibility

  • Python: 3.8+ (Python 2 support removed in v0.2.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 represents 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

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.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 facterpy 1.0.0
File Size Uploaded
facterpy-1.0.0.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for facterpy 1.0.0
File Interpreter ABI Platform
facterpy-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / facterpy-1.0.0.tar.gz

Download URL facterpy-1.0.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a2cdde974e795621af9295bd6c4b6eea2ab29f92ecb77415890098de8dc27c4e
BLAKE2b-256 checksum
How to use checksums
fcab14fb8ad1822522bfc767e2f9465f0c6449d2a5b6e5f225c07d45257586a0
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

Release files / facterpy-1.0.0-py3-none-any.whl

Download URL facterpy-1.0.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
421c7d6bc847b279bc77a11d0ff3b372fb2812e3ba7b9f6b2b28ffa34fb55045
BLAKE2b-256 checksum
How to use checksums
7aa43208910defbc81e2237db0b0cf96cad0c6a80f7a0c2f005299108c5c8c11
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

Release history Release notifications | RSS feed

1.1.0

2 release files

This release

1.0.0 This release

2 release files

0.1

1 release file

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