Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Osquery Python API

Project Description

## osquery-python


[osquery]( exposes an operating system as a high-performance relational database. This allows you to write SQL-based queries to explore operating system data. With osquery, SQL tables represent abstract concepts such as running processes, loaded kernel modules, open network connections, browser plugins, hardware events or file hashes.

If you're interested in learning more about osquery, visit the [GitHub project](, the [website](, and the [users guide](

### What is osquery-python?

[![Build Status](](

In osquery, SQL tables, configuration retrieval, log handling, etc are implemented via a simple, robust plugin and extensions API. This project contains the official Python bindings for creating osquery extensions in Python. Consider the following example:

#!/usr/bin/env python

import osquery

class MyTablePlugin(osquery.TablePlugin):
def name(self):
return "foobar"

def columns(self):
return [
osquery.TableColumn(name="foo", type=osquery.STRING),
osquery.TableColumn(name="baz", type=osquery.STRING),

def generate(self, context):
query_data = []

for _ in range(2):
row = {}
row["foo"] = "bar"
row["baz"] = "baz"

return query_data

if __name__ == "__main__":
osquery.start_extension(name="my_awesome_extension", version="1.0.0")

To test this code start an osquery shell:

osqueryi --nodisable_extensions
osquery> select value from osquery_flags where name = 'extensions_socket';
| value |
| /Users/USERNAME/.osquery/shell.em |

Then start the Python extension:

python ./ --socket /Users/USERNAME/.osquery/shell.em

Alternatively, you can also autoload your extension when starting an osquery shell:

osqueryi --extension

This will register a table called "foobar". As you can see, the table will return two rows:

osquery> select * from foobar;
| foo | baz |
| bar | baz |
| bar | baz |

This is obviously a contrived example, but it's easy to imagine the possibilities.

Using the instructions found on the [wiki](, you can easily deploy your extension with an existing osquery deployment.

Extensions are the core way that you can extend and customize osquery. At Facebook, we use extensions extensively to implement many plugins that take advantage of internal APIs and tools.

### Execute queries in Python

The same Thrift bindings can be used to create a Python client for the `osqueryd` or `osqueryi`'s extension socket. There are helper classes provided that spawn an ephemeral osquery process for consecutive or long running client instances.

import osquery

if __name__ == "__main__":
# Spawn an osquery process using an ephemeral extension socket.
instance = osquery.SpawnInstance()

# Issues queries and call osquery Thrift APIs.
instance.client.query("select timestamp from time")

### Install

To install from PyPi, run the following:

pip install osquery

Alternatively, to install from this repo, run the following:

python build
python install

### Development

See []( and the [osquery wiki]( for development information.

### Vulnerabilities

Facebook has a [bug bounty]( program that includes osquery. If you find a security vulnerability in osquery, please submit it via the process outlined on that page and do not file a public issue. For more information on finding vulnerabilities in osquery, see a recent blog post about [bug-hunting osquery](

Release History

This version
History Node


History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(16.6 kB) Copy SHA256 Hash SHA256
Source None Oct 4, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers