Skip to content

opengovern/og_query_runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Opengovernance Query Runner Package

Installation

Clone the repository

git clone https://github.com/opengovern/og_query_runner.git

Install the package

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

from og_query_runner import RunQuery

response = RunQuery("https://instance_url", "SELECT * FROM table", "api_key")
print(response)

Output

{
    "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

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

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

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 that demonstrates how to use the package.

License

see the LICENSE file for details.

About

Python package for running a given query on a opensecurity instance

Topics

Resources

License

Stars

Watchers

Forks

Languages