# This is an automatically generated code sample.
# To make this code sample work in your Oracle Cloud tenancy,
# please replace the values for any parameters whose current values do not fit
# your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
# boolean, number, and enum parameters with values not fitting your use case).

import oci
from datetime import datetime

# Create a default config using DEFAULT profile in default location
# Refer to
# https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File
# for more info
config = oci.config.from_file()


# Initialize service client with default config file
usage_api_client = oci.usage_api.UsageapiClient(config)


# Send the request to service, some parameters are not required, see API
# doc for more info
create_query_response = usage_api_client.create_query(
    create_query_details=oci.usage_api.models.CreateQueryDetails(
        compartment_id="ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
        query_definition=oci.usage_api.models.QueryDefinition(
            display_name="EXAMPLE-displayName-Value",
            report_query=oci.usage_api.models.ReportQuery(
                tenant_id="ocid1.test.oc1..<unique_ID>EXAMPLE-tenantId-Value",
                granularity="DAILY",
                time_usage_started=datetime.strptime(
                    "2006-08-27T08:22:30.548Z",
                    "%Y-%m-%dT%H:%M:%S.%fZ"),
                time_usage_ended=datetime.strptime(
                    "2047-11-09T13:22:26.472Z",
                    "%Y-%m-%dT%H:%M:%S.%fZ"),
                is_aggregate_by_time=True,
                forecast=oci.usage_api.models.Forecast(
                    time_forecast_ended=datetime.strptime(
                        "2049-03-11T09:23:26.888Z",
                        "%Y-%m-%dT%H:%M:%S.%fZ"),
                    forecast_type="BASIC",
                    time_forecast_started=datetime.strptime(
                        "2011-09-27T09:18:59.045Z",
                        "%Y-%m-%dT%H:%M:%S.%fZ")),
                query_type="EXPIREDCREDIT",
                group_by=["EXAMPLE--Value"],
                group_by_tag=[
                    oci.usage_api.models.Tag(
                        namespace="EXAMPLE-namespace-Value",
                        key="EXAMPLE-key-Value",
                        value="EXAMPLE-value-Value")],
                compartment_depth=5.4588947,
                filter=oci.usage_api.models.Filter(
                    operator="NOT",
                    dimensions=[
                        oci.usage_api.models.Dimension(
                            key="EXAMPLE-key-Value",
                            value="EXAMPLE-value-Value")],
                    tags=[
                        oci.usage_api.models.Tag(
                            namespace="EXAMPLE-namespace-Value",
                            key="EXAMPLE-key-Value",
                            value="EXAMPLE-value-Value")]),
                date_range_name="LAST_TWO_MONTHS"),
            cost_analysis_ui=oci.usage_api.models.CostAnalysisUI(
                graph="LINES",
                is_cumulative_graph=True),
            version=9851.71)),
    opc_request_id="5MV935SGYND2DZOQERJY<unique_ID>",
    opc_retry_token="EXAMPLE-opcRetryToken-Value")

# Get the data from response
print(create_query_response.data)