Registry / devops / osquery

osquery

JSON →
library3.1.1pypypi✓ verified 83d ago

The `osquery` Python library provides a robust API for interacting with the osquery daemon, enabling users to execute SQL queries against the operating system, manage osquery extensions, and handle distributed queries. It acts as a client to a running `osqueryd` instance. The current version is 3.1.1, released in December 2023, with releases occurring periodically to keep pace with the core osquery project.

pip install osquery
INSTALL
IMPORT
SIG · OSQUERY
O
osquery
devopspythonv3.1.1
Install
3.9s avg
Import
107ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.110s · 22.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.9s · import 0.104s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ExtensionClient
from osquery import ExtensionClient
import osquery; client = osquery.Client()
ExtensionManager
from osquery import ExtensionManager
SpawnInstance
from osquery import SpawnInstance

This quickstart demonstrates how to initialize an osquery client and execute a basic SQL query. It expects an osquery daemon to be running and accessible via its default Unix socket. Error handling is included for common connection issues.

import osquery import sys try: # Create an osquery client. # By default, it tries to connect to the osquery socket at /var/osquery/osquery.em # Ensure the osquery daemon is running and configured to use a socket. # If the daemon uses a non-default socket, pass the path: osquery.Client(path='/path/to/socket.em') client = osquery.Client() # Execute a simple SQL query query = "SELECT name, version FROM osquery_info;" response = client.query(query) print(f"Query: {query}") print(f"Status: {response.status}") if response.status: print(f"Results: {response.response}") else: print(f"Error: {response.error}") print("Make sure the osquery daemon is running and accessible.") except ConnectionRefusedError: print("Error: Could not connect to osquery daemon. Is it running?", file=sys.stderr) sys.exit(1) except FileNotFoundError: print("Error: Osquery socket not found. Is osquery daemon running and configured?", file=sys.stderr) sys.exit(1) except Exception as e: print(f"An unexpected error occurred: {e}", file=sys.stderr) sys.exit(1)
Debug
Known issues
breakingThe primary API for running queries changed from direct `osquery.query()` calls to using an `osquery.Client()` instance.
fix
Initialize `client = osquery.Client()` and then call `client.query(...)`.
affects: >=2.0.0
breakingThe `osquery.extensions` module was moved to `osquery.api.extensions` to better align with the core C++ project structure.
fix
Update imports from `from osquery import extensions` to `from osquery.api import extensions`.
affects: >=3.0.0
gotchaThe `osquery` Python library is a client to the `osqueryd` daemon. It requires a running `osqueryd` instance to function, typically communicating via a Unix socket. Without `osqueryd` running, all client operations will fail with connection errors.
fix
Ensure the `osqueryd` daemon is installed, running, and its socket path is correctly configured and accessible by the Python process (e.g., `/var/osquery/osquery.em` on Linux/macOS). If a custom socket path is used, pass it to `osquery.Client(path='...')`.
affects: All versions
Upgrade
Version history
3.1.1latest on PyPI · released Jul 24, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources
osquery — pip install osquery · libregistry