Osquery Python API
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install osqueryosquery-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?
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
@osquery.register_plugin
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"
query_data.append(row)
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 ./my_table_plugin.py --socket /Users/USERNAME/.osquery/shell.em
Alternatively, you can also autoload your extension when starting an osquery shell:
osqueryi --extension path_to_my_table_plugin.py
This will register a table called "foobar". As you can see, the table will return two rows: