Skip to main content

This is a openapi helper library for the ZMP AI Platform

Project description

axmp-openapi-helper

Platform Badge Component Badge CI Badge License Badge PyPI - Version PyPI - Implementation PyPI - Python Version PyPI - Wheel PyPI - Download

Introduction

This is a openapi helper library for the ZMP AI Platform

Key Features

  • Support the OpenAPI Specification(>=3.0.0)
  • Generate the Arguments Schema for the LLM

Installation

Install using pip:

pip install axmp-openapi-helper

Install using poetry:

poetry add axmp-openapi-helper

Usage

Basic example:

import logging
import logging.config

from axmp_openapi_helper import (
    MixedAPISpecConfig,
    ZmpAPIWrapper,
)

logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
logging.getLogger("axmp_openapi_helper.openapi.zmpapi_models").setLevel(logging.INFO)
logging.getLogger("axmp_openapi_helper.toolkits.toolkit").setLevel(logging.INFO)
logger = logging.getLogger("appLogger")
logger.setLevel(logging.DEBUG)

if __name__ == "__main__":
    mixed_api_spec_config = MixedAPISpecConfig.from_mixed_spec_file(
        file_path="runner/openapi/zmp_mixed_api_spec.json"
    )

    zmp_api_wrapper = ZmpAPIWrapper(
        "https://api.test.company.com",
        mixed_api_spec_config=mixed_api_spec_config,
        auth_type=AuthenticationType.CUSTOM,
        custom_auth_header_key="X-Access-Key",
        custom_auth_header_value="xxxxx",
    )

    operations = zmp_api_wrapper.get_operations()
    for operation in operations:
        print("-" * 100)
        print(operation.args_schema)
        for field_name, field_info in operation.args_schema.model_fields.items():
            print(
                f"\t{field_name}: {field_info.annotation}, {field_info.default}, {field_info.description}"
            )

    response = zmp_api_wrapper.run(
        "GET",
        "/api/alert/v1/alerts",
        query_params=None
    )
    print(response)

Mixed API Spec Config Sample

{
    "backends": [
        {
            "backend": "zcp-alert-backend",
            "config": {
                "file_path": "runner/openapi/zcp/zcp_alert_backend_openapi_spec.json",
                "prefix": "/api/alert/v1",
                "apis": [
                    {
                        "path":"/api/alert/v1/alerts",
                        "methods": ["get"]
                    },
                    {
                        "path":"/api/alert/v1/alerts",
                        "methods": ["post"]
                    },
                    {
                        "path":"/api/alert/v1/alerts/{alert_id}",
                        "methods": ["get"]
                    },
                    {
                        "path":"/api/alert/v1/alerts/webhook",
                        "methods": ["post"]
                    },
                    {
                        "path":"/api/alert/v1/alerts/{alert_id}/{action}",
                        "methods": ["patch"]
                    },
                    {
                        "path":"/api/alert/v1/alerts/bulk/{action}",
                        "methods": [
                            {
                                "method": "patch",
                                "description": "Bulk action on alerts"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "backend": "zcp-mcm-backend",
            "config": {
                "file_path": "runner/openapi/zcp/zcp_mcm_backend_openapi_spec.json",
                "prefix": "/api/mcm/resource/v1beta1",
                "apis": [
                    {
                        "path":"/api/mcm/resource/v1beta1/workload/pods",
                        "methods": [
                            {
                                "method": "get",
                                "description": "Get pods using the query parameters"
                            }
                        ]
                    },
                    {
                        "path":"/api/mcm/resource/v1beta1/workload/pods/{name}",
                        "methods": [
                            {
                                "method": "get",
                                "description": "Get pod details by name and cluster and namespace parameters"
                            }
                        ]
                    },
                    {
                        "path":"/api/mcm/resource/v1beta1/workload/pods/events",
                        "methods": [
                            {
                                "method": "get",
                                "description": "Get pod events by id which is consists of cluster, namespace and pod name. seperated by $. e.g.)id=cluster1$namespace1$pod1"
                            }
                        ]
                    },
                    {
                        "path":"/api/mcm/resource/v1beta1/workload/pods/metrics",
                        "methods": [
                            {
                                "method": "get",
                                "description": "Get pod metrics by id which is consists of cluster, namespace and pod name. seperated by $. e.g.)id=cluster1$namespace1$pod1"
                            }
                        ]
                    },
                    {
                        "path":"/api/mcm/resource/v1beta1/accesscontrol/clusterrolebindings",
                        "methods": ["get", "delete"]
                    },
                    {
                        "path":"/api/mcm/resource/v1beta1/clusters",
                        "methods": [
                            {
                                "method":   "get",
                                "description": "Get clusters using the query parameters"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "backend": "zcp-monitoring-backend",
            "config": {
                "file_path": "runner/openapi/zcp/zcp_monitoring_backend_openapi_spec.json",
                "prefix": "/api/monitoring/v1beta1",
                "apis": [
                    {
                        "path":"/api/monitoring/v1beta1/realms/{realm}/rules/{namespace}",
                        "methods": [
                            {
                                "method": "get",
                                "description": "Get rule groups by realm and namespace"
                            }
                        ]
                    },
                    {
                        "path":"/api/monitoring/v1beta1/realms/{realm}/events",
                        "methods": [
                            {
                                "method": "get",
                                "description": "Get events by realm"
                            }
                        ]
                    },
                    {
                        "path":"/api/monitoring/v1beta1/realms/{realm}/metrics/clusters",
                        "methods": [
                            {
                                "method": "get",
                                "description": "Get metrics of clusters by realm"
                            }
                        ]
                    },
                    {
                        "path":"/api/monitoring/v1beta1/realms/{realm}/metrics/nodes",
                        "methods": [
                            {
                                "method": "get",
                                "description": "Get metrics of nodes by realm"
                            }
                        ]
                    },
                    {
                        "path":"/api/monitoring/v1beta1/realms/{realm}/metrics/pods",
                        "methods": [
                            {
                                "method": "get",
                                "tool_name": "get_metrics_of_pods_by_realm",
                                "description": "Get metrics of pods by realm"
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

For more detailed usage instructions, please refer to our documentation.

Development Setup

  1. Clone the repository
git clone https://github.com/yourusername/axmp-openapi-helper.git
cd axmp-openapi-helper
  1. Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # Windows: venv\Scripts\activate
  1. Install development dependencies
poetry install

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

axmp_openapi_helper-0.1.0.tar.gz (106.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

axmp_openapi_helper-0.1.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file axmp_openapi_helper-0.1.0.tar.gz.

File metadata

  • Download URL: axmp_openapi_helper-0.1.0.tar.gz
  • Upload date:
  • Size: 106.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for axmp_openapi_helper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ae5b4c60a80df14641b54e6a9908089948378f73b996affff8756e8cfa55c3b1
MD5 d87563a84563eb1399fac4b5be0cef75
BLAKE2b-256 e77705ecd51cfd1fa860960c7bea9571aa94b02ff1eac1dbda0d2a54c99fea5b

See more details on using hashes here.

File details

Details for the file axmp_openapi_helper-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for axmp_openapi_helper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b370eca08509a9162de9151255601ac5347376e59c2adba0325e097fa07b8574
MD5 e0f077c819dcef53f66121a3db063501
BLAKE2b-256 43ff425abb5f9f0b056391900aa73e5d05282ac2b36839ae21b4858580225766

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page