Skip to main content

Accounting Library

The ARGO Accounting Library is a lightweight Python library (adapter) that provides a convenient interface for interacting with the ARGO Accounting Service REST API. It is designed to be used by infrastructure providers, service operators, and service components that need to retrieve or push metrics or information related to installations, providers, and projects.

The library's source code and examples are available on GitHub.

Overview

The Accounting System is responsible for collecting, aggregating, and exchanging accounting metrics across different infrastructures and stakeholders. The Accounting Library acts as a client-side adapter that:

  • Authenticates against the ARGO Accounting Service
  • Retrieves registered entities (installations, projects, providers)
  • Fetches accounting metrics
  • Pushes new metric values to the service

The library wraps the Accounting Service REST API and abstracts HTTP calls, authentication headers, and response handling.

Supported Environments

The library has been tested with:

  • Python: 3.9, 3.11, 3.12
  • Operating Systems: Rocky Linux 9 (RHEL-compatible systems)

Installation

From Source

Clone the repository and install using setuptools:

python3 ./setup.py build && sudo python3 ./setup.py install

RPM-based Installation (RHEL / Rocky / Alma)

You can also build an RPM package:

python3 ./setup.py build && sudo python3 ./setup.py bdist_rpm

Install the generated RPM (located under dist/):

sudo dnf install ./dist/argo-acc-library-<version>.noarch.rpm

Authentication

The Accounting Library uses JWT-based authentication.

A valid JSON Web Token (JWT) with one-hour validity must be obtained by following the instructions in the Authenticating Clients section.

Once a token is available, initialize the Accounting Service client:

from argo_acc_library import ArgoAccountingService

acc = ArgoAccountingService(
endpoint="https://api.devel.acc.argo.grnet.gr",
token="<your_jwt>"
)

Replace the endpoint with the appropriate environment (e.g., production: https://api.acc.argo.grnet.gr).

Usage Examples

The repository's examples directory contains practical, ready-to-run scripts that showcase common use cases. These scripts leverage the library's Python code to perform various actions.

All examples support the --help flag for detailed usage instructions.

Prerequisites

Save your valid JWT token in a file, e.g., ~/acc.jwt.

1. List Registered Projects

This example (get_projects.py) retrieves the list of all registered Projects and iterates over them, printing each project’s identifier and title.

python3 examples/get_projects.py \
--host api.devel.acc.argo.grnet.gr \
--token ~/acc.jwt -f

2. List Registered Providers

This example (get_providers.py) queries the Accounting Service for all registered Providers and iterates over them to print their identifiers and names.

python3 examples/get_providers.py \
--host api.devel.acc.argo.grnet.gr \
--token ~/acc.jwt -f

3. List Registered Installations

This example (get_installations.py) retrieves all registered Installations from the Accounting Service and iterates over the result set, printing the installation attributes as JSON string.

python3 examples/get_installations.py \
--host api.devel.acc.argo.grnet.gr \
--token ~/acc.jwt -f

4. Retrieve Metrics for a Project

This example (get_project_metrics.py) fetches all metrics associated with a specific Project and loops over the results to inspect metric definitions and reported values.

python3 examples/get_project_metrics.py \
--host api.devel.acc.argo.grnet.gr \
--token ~/acc.jwt -f \
--project <PROJECT_ID>

5. Retrieve Metrics for a Provider under a specific Project

This example (get_provider_metrics.py) fetches all metrics associated with a specific Provider under a specific Project and loops over the results to inspect metric definitions and reported values.

python3 examples/get_provider_metrics.py \
--host api.devel.acc.argo.grnet.gr \
--token ~/acc.jwt -f \
--project <PROJECT_ID> \
--provider <PROVIDER_ID>

6. Retrieve Metrics for an Installation

This example (get_installation_metrics.py) queries all accounting metrics associated with a specific Installation and loops over them to display the metric definition identifiers and their corresponding values.

python3 examples/get_installation_metrics.py \
--host api.devel.acc.argo.grnet.gr \
--token ~/acc.jwt -f \
--installation <INSTALLATION_ID>

7. Push Installation Metrics

This example (add_installation_metric.py) demonstrates how to submit (push) a new metric entry for a given Installation by providing the metric definition, time window, value, and user/group context.

python3 examples/add_installation_metric.py \
--host api.devel.acc.argo.grnet.gr \
--token ~/acc.jwt -f \
--installation <INSTALLATION_ID> \
--metricdefid <METRICDEF_ID> \
--tstart <TSTART> \
--tend <TEND> \
--value <VALUE> \
--gid <GID> \
--uid <UID>

Environment Variables

The Accounting Library supports the following environment variables:

VariableDescription
DEBUGSet to any truthy value to enable verbose debug output

Example:

export DEBUG=true

Error Handling

The library propagates HTTP and validation errors returned by the Accounting Service. Users are encouraged to:

  • Validate entity IDs before metric submission
  • Handle empty or partial responses
  • Enable DEBUG mode during development

Python API

Core Service & HTTP Layer

ClassPurposeAttributesMethods / Properties
ArgoAccountingServiceEntry point for accessing the Accounting REST API_endpoint, _conn, _installations, _projects, _providersinstallations, projects, providers, connection, endpoint
HttpRequestsLow-level HTTP request handlertoken, routesmake_request(), _error_dict()

Exceptions

ClassPurposeAttributesMethods
AccExceptionBase exception for accounting errors__init__()
AccServiceExceptionAPI-level errorsmsg, code__init__()
AccTimeoutExceptionTimeout-specific API errors__init__()
AccConnectionExceptionNetwork/connection errorsmsg__init__()

REST Resource Base Classes

ClassPurposeAttributesMethods
RestResourceAbstract base for all REST resources_parentendpoint, connection, id_name, data_root
RestResourceItemRepresents a single REST resourceid (dynamic fields via JSON)_fetch(), _fetch_route(), _fetch_args(), __str__()
RestResourceListRepresents paginated REST collections_parent, _page_size, _page_count, _current_page, _cache_fetch(), _fetch_route(), _fetch_args(), _create_child(), refresh(), add(), __iter__(), __getitem__(), get()

Installation Domain

ClassPurposeAttributesMethods / Properties
InstallationBaseBase class for installationsid, project, organisation, infrastructure, installation, resource, unit_of_access
InstallationSingle installation(inherits base fields)_fetch_route(), _fetch_args(), metrics
InstallationsCollection of installations_fetch_route(), _fetch_args(), _create_child()
ProjectInstallationInstallation under a project(inherits base fields)metrics
ProjectInstallationsProject installation collection_fetch_route(), _fetch_args(), _create_child()
ProjectProviderInstallationInstallation under project & provider(inherits base fields)metrics
ProjectProviderInstallationsProvider-scoped installations_fetch_route(), _fetch_args(), _create_child()

Metrics Domain

ClassPurposeAttributesMethods
MetricBaseBase class for metricsid, time_period_start, time_period_end, value, project, provider, installation_id, project_id, resource, group_id, user_id, metric_definition_id, metric_definition
MetricDefinitionMetric definition metadatametric_definition_id, metric_name, metric_description, unit_type, metric_type, creator_id_fetch_route(), _fetch_args()
MetricsBase metrics collection
InstallationMetricMetric for an installation_fetch_route(), _fetch_args()
InstallationMetricsInstallation metric collection_fetch_route(), _fetch_args(), _add_route(), _add_args(), _create_child()
ProjectMetricMetric for a project
ProjectMetricsProject metric collection_fetch_route(), _fetch_args(), _create_child()
ProviderMetricMetric for a provider
ProviderMetricsProvider metric collection_fetch_route(), _fetch_args(), _create_child()

Projects Domain

ClassPurposeAttributesMethods / Properties
ProjectSingle projectid, acronym, title, start_date, end_date, call_identifier, _providers_fetch_route(), _fetch_args(), providers, metrics, installations
ProjectsProject collection_fetch_route(), _fetch_args(), _create_child()

Providers Domain

ClassPurposeAttributesMethods / Properties
ProviderSingle providerid, acronym, title, start_date, end_date, call_identifier, providers_fetch_route(), _fetch_args(), metrics
ProvidersProvider collection_fetch_route(), _fetch_args(), _create_child()
ProjectProviderProvider within a project contextmetrics, installations
ProjectProvidersProject-scoped provider collection__getitem__()