zmp-openapi-helper
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 zmp-openapi-helper
Install using poetry:
poetry add zmp-openapi-helper
Usage
Basic example:
import logging
import logging.config
from zmp_openapi_helper import (
MixedAPISpecConfig,
ZmpAPIWrapper,
)
logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
logging.getLogger("zmp_openapi_helper.openapi.zmpapi_models").setLevel(logging.INFO)
logging.getLogger("zmp_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
- Clone the repository
git clone https://github.com/yourusername/zmp-openapi-helper.git
cd zmp-openapi-helper
- Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: venv\Scripts\activate
- Install development dependencies
poetry install
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
- Issue Tracker: https://github.com/cloudz-mp/zmp-openapi-helper/issues
- Email: kilsoo75@gmail.com
Metadata
Release files for zmp-openapi-helper 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zmp_openapi_helper-0.2.1.tar.gz | 16.6 kB | Without provenance | Details for zmp_openapi_helper-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zmp_openapi_helper-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for zmp_openapi_helper-0.2.1-py3-none-any.whl |
Total release size: 34.7 kB
Release files / zmp_openapi_helper-0.2.1.tar.gz
| Download URL | zmp_openapi_helper-0.2.1.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6d093d95236ebb05dff6d3a60d527c4ee26f9181047e7361124ee5de2064723
|
|
BLAKE2b-256 checksum How to use checksums |
e4e53aedb6b617f8ffe2212ce4e6a06a584fcf498c43c2568d3fd5500268a5c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.11.10 Darwin/24.3.0
|
Release files / zmp_openapi_helper-0.2.1-py3-none-any.whl
| Download URL | zmp_openapi_helper-0.2.1-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b437305f581f7f49fef3e7bf7a6f1f983dc8befba68419ae159714a7801a0eae
|
|
BLAKE2b-256 checksum How to use checksums |
53bb025483645197584784a7ccd27121bb27d2fbf3fa438d175552ff05af03b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.11.10 Darwin/24.3.0
|
Security for zmp-openapi-helper 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.