https://github.com/opengovern/og_query_runner
Python package for running a given query on a opensecurity instance
https://github.com/opengovern/og_query_runner
pip python3
Last synced: 9 months ago
JSON representation
Python package for running a given query on a opensecurity instance
- Host: GitHub
- URL: https://github.com/opengovern/og_query_runner
- Owner: opengovern
- License: other
- Created: 2025-03-08T08:02:17.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-03-08T10:22:28.000Z (9 months ago)
- Last Synced: 2025-03-08T10:26:53.600Z (9 months ago)
- Topics: pip, python3
- Language: Python
- Homepage: https://www.opensecurity.sh
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Opengovernance Query Runner Package
- [Opengovernance Query Runner Package](#opengovernance-query-runner-package)
- [Installation](#installation)
- [Clone the repository](#clone-the-repository)
- [Install the package](#install-the-package)
- [Functions](#functions)
- [RunQuery](#runquery)
- [Parameters](#parameters)
- [Returns](#returns)
- [Example](#example)
- [Output](#output)
- [SaveQueryResults](#savequeryresults)
- [Parameters](#parameters-1)
- [Returns](#returns-1)
- [Example](#example-1)
- [RunAndSaveQuery](#runandsavequery)
- [Parameters](#parameters-2)
- [Returns](#returns-2)
- [Example](#example-2)
- [ReadQueryFromFile](#readqueryfromfile)
- [Parameters](#parameters-3)
- [Returns](#returns-3)
- [Example](#example-3)
- [Example File](#example-file)
- [License](#license)
## Installation
### Clone the repository
```bash
git clone https://github.com/opengovern/og_query_runner.git
```
### Install the package
```bash
pip install .
```
## Functions
- RunQuery
- SaveQueryResults
- RunAndSaveQuery
- ReadQueryFromFile
## RunQuery
Executes a query on a given instance URL using an API key.
### Parameters
- `instance_url`: string
- The base URL of the instance where the query will be executed.
- `query`: string
- The query string to be executed.
- `api_key`: string
- The API key for authentication.
### Returns
- `dict`
- The results of the query as a JSON object.
### Example
```python
from og_query_runner import RunQuery
response = RunQuery("https://instance_url", "SELECT * FROM table", "api_key")
print(response)
```
### Output
```json
{
"headers": ["column1", "column2"],
"result": [["x", "y"], ["a", "b"]]
}
```
## SaveQueryResults
Saves query results to a CSV file and optionally saves the query itself.
### Parameters
- `data`: dict
- The results of the query, including headers and result rows.
- `file_path`: string
- The filename (without `.csv`) where the results will be saved.
- `query`: string (optional)
- The query string to be saved.
### Returns
- None
### Example
```python
from og_query_runner import SaveQueryResults
SaveQueryResults({
"headers": ["column1", "column2"],
"result": [["x", "y"], ["a", "b"]]
}, "results")
```
## RunAndSaveQuery
Executes a query and saves the results to a CSV file.
### Parameters
- `instance_url`: string
- The base URL of the instance where the query will be executed.
- `query`: string
- The query string to be executed.
- `api_key`: string
- The API key for authentication.
- `file_path`: string
- The filename (without `.csv`) where the results will be saved.
### Returns
- None
### Example
```python
from og_query_runner import RunAndSaveQuery
RunAndSaveQuery("https://instance_url", "SELECT * FROM table", "api_key", "results")
```
## ReadQueryFromFile
Reads a query result from a CSV file and reconstructs it in the same format as `RunQuery`.
### Parameters
- `file_path`: string
- The path to the CSV file (without `.csv`) containing the query result.
### Returns
- `dict`
- A dictionary with 'headers' (list of column names) and 'result' (list of row values).
### Example
```python
from og_query_runner import ReadQueryFromFile
result = ReadQueryFromFile("results")
print(result)
```
## Example File
you can find an example file in the repository named [example.py](example.py) that demonstrates how to use the package.
## License
see the [LICENSE](LICENSE) file for details.