Skip to main content

Python wrapper for puppetDB API

Project description

Puppetdb-api is python API around the puppetDB REST API.


Nodes, facts and resources can by queried by matching nodes, facts and resources with boolean operators or, and and not.

All the queries can be done as a raw queries, to obtain the raw JSON, that puppetDB returns.


>>> p = PuppetDB('')
>>> p.nodes(Or(Fact('role', 'example', '='), Resource('Class', 'Klass_name', '=')))
[u'', u'']
>>> p.nodes_raw(Node('', '='))
[{u'deactivated': None, u'facts_timestamp': u'2014-08-25T19:45:00.707Z', u'name': u'', u'report_timestamp': u'2014-08-25T19:46:09.616Z', u'catalog_timestamp': u'2014-08-25T19:45:14.896Z'}]


Values for multiple facts can be obtained by passing multiple facts names to facts argument.

>>> p = PuppetDB('')
>>> p.facts(query=And(Fact('role', 'example', '='), Not(Resource('Class', 'Klass_name', '='))), facts=['role', 'hostname'])
{u'hostname': [u'hostname1'], u'role': [u'example']}
>>> p.facts_raw(Node('', '~'))
[{u'certname': u'', u'name': u'clientversion', u'value': u'3.8.7'}, {u'certname': u'', u'name': u'uptime_hours', u'value': u'656'}]


Values for multiple resources can be obtained by passing multiple resources names to resources argument.

>>> p = PuppetDB('')
>>> p.resources(query=And(Fact('role', 'example', '='), Not(Resource('Class', 'Klass_name', '='))), resources=['Some_resource'])
{u'Some_resource': [u'Resource_title']}
>>> p.resources_raw(query=Node('', '~'), resources=['Some_resource'])
[{u'certname': u'', u'resource': u'8df598f3923a05e543e884d247d74cac08087a45', u'parameters': {}, u'title': u'resource_title', u'tags': [u'tag1', u'tag2'], u'exported': False, u'file': u'/etc/puppet/environments/example/example.pp', u'line': 25, u'type': u'Some_resource'}]


$ pip install puppetdb_api

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

puppetdb_api-1.1.tar.gz (6.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page