The Octane Python library provides programmatic access to the Octane API for Python applications.
First, install the package (octane):
pip install --upgrade octaneNext, obtain an API key from within the Octane portal, and set it in your environment:
export OCTANE_API_KEY="<insert_octane_api_key_here>"Then, from within your application, import the module:
import os, octane
octane.api_key = os.getenv("OCTANE_API_KEY")The following demo applications found in the examples/ directory display how to use the Octane Python library in real-world settings:
- antler-db-cloud-shop - Enable your customers to self-service various cloud resources
- customer-hours-tracker - Track hours spent working on freelance projects
The octane instance provides programmatic access to the Octane API.
The Customer namespace on the octane instance provides the ability to
make calls to the Octane Customers API.
customer_name = "r2d2"
octane.Customer.create(
name=customer_name,
measurement_mappings=[{
"label": "customer_name",
"value_regex": customer_name
}]
)customer_name = "r2d2"
price_plan_name = "droidplan"
octane.Customer.create_subscription(customer_name, price_plan_name=price_plan_name)The Meter namespace on the octane instance provides the ability to
make calls to the Octane Meters API.
meter_name = "droidrepairs"
octane.Meter.create(
name=meter_name,
meter_type="COUNTER",
is_incremental=True,
expected_labels=["customer_name"]
)The PricePlan namespace on the octane instance provides the ability to
make calls to the Octane Price Plans API.
price_plan_name = "droidplan"
price_plan_rate = 10000 # $100.00
meter_name = "droidrepairs"
octane.PricePlan.create(
name=price_plan_name,
period="month",
metered_components=[{
"meter_name": meter_name,
"price_scheme": {
"prices": [{
"price": price_plan_rate
}],
"scheme_type": "FLAT"
}
}]
)The Measurement namespace on the octane instance provides the ability to
make calls to the Octane Measurements API.
meter_name = "droidrepairs"
customer_name = "r2d2"
octane.Measurement.create(
meter_name=meter_name,
customer_name=customer_name,
value=1,
)meter_name = "droidrepairs"
customer_name = "r2d2"
octane.Measurement.create_multi(
measurements=[
{
"meter_name": meter_name,
"customer_name": customer_name,
"value": 1,
"time": "2023-01-01T00:00:00",
},
{
"meter_name": meter_name,
"customer_name": customer_name,
"value": 1,
"time": "2023-01-02T00:00:00",
},
]
)Run the following command to set up the development virtualenv:
makeRun all tests on all supported Python versions:
make testRun all tests for a specific Python version (modify -e according to your Python target):
TOX_ARGS="-e py37" make testRun all tests in a single file:
TOX_ARGS="-e py37 -- tests/api_resources/abstract/test_updateable_api_resource.py" make testRun a single test suite:
TOX_ARGS="-e py37 -- tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource" make testRun a single test:
TOX_ARGS="-e py37 -- tests/api_resources/abstract/test_updateable_api_resource.py::TestUpdateableAPIResource::test_save" make testRun the linter with:
make lintThe library uses Black for code formatting. Code must be formatted with Black before PRs are submitted, otherwise CI will fail. Run the formatter with:
make fmtContributions are welcome!
Prior to submitting a pull request, please check the list of open issues. If there is not an existing issue related to your changes, please open a new issue to first discuss your thoughts with the project maintainers.
