git clone https://github.com/opengovern/og_query_runner.git
pip install .
- RunQuery
- SaveQueryResults
- RunAndSaveQuery
- ReadQueryFromFile
Executes a query on a given instance URL using an API key.
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.
dict
- The results of the query as a JSON object.
from og_query_runner import RunQuery
response = RunQuery("https://instance_url", "SELECT * FROM table", "api_key")
print(response)
{
"headers": ["column1", "column2"],
"result": [["x", "y"], ["a", "b"]]
}
Saves query results to a CSV file and optionally saves the query itself.
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.
- The filename (without
query
: string (optional)- The query string to be saved.
- None
from og_query_runner import SaveQueryResults
SaveQueryResults({
"headers": ["column1", "column2"],
"result": [["x", "y"], ["a", "b"]]
}, "results")
Executes a query and saves the results to a CSV file.
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.
- The filename (without
- None
from og_query_runner import RunAndSaveQuery
RunAndSaveQuery("https://instance_url", "SELECT * FROM table", "api_key", "results")
Reads a query result from a CSV file and reconstructs it in the same format as RunQuery
.
file_path
: string- The path to the CSV file (without
.csv
) containing the query result.
- The path to the CSV file (without
dict
- A dictionary with 'headers' (list of column names) and 'result' (list of row values).
from og_query_runner import ReadQueryFromFile
result = ReadQueryFromFile("results")
print(result)
you can find an example file in the repository named example.py that demonstrates how to use the package.
see the LICENSE file for details.