Metadata-Version: 2.4
Name: cloudvision
Version: 1.29.1
Summary: A Python library for Arista's CloudVision APIs and Provisioning Action integrations.
Maintainer-email: Support <support@arista.com>
Project-URL: Documentation, https://aristanetworks.github.io/cloudvision-python/
Project-URL: Source, https://github.com/aristanetworks/cloudvision-python
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10.0
Description-Content-Type: text/markdown
License-File: COPYING
Requires-Dist: aristaproto==0.1.4
Requires-Dist: cryptography==46.0.7
Requires-Dist: grpcio>=1.53.0
Requires-Dist: msgpack>=1.0.3
Requires-Dist: protobuf<6.0dev,>=5.28.3
Requires-Dist: pyavd-utils==0.0.1
Requires-Dist: requests>=2.20.1
Requires-Dist: typing-extensions>=4.2.0
Provides-Extra: dev
Requires-Dist: isort==5.11.4; extra == "dev"
Requires-Dist: black==26.3.1; extra == "dev"
Requires-Dist: mypy-protobuf==3.6.0; extra == "dev"
Requires-Dist: mypy==0.981; extra == "dev"
Requires-Dist: pytest==9.0.3; extra == "dev"
Requires-Dist: pytest-asyncio==1.3.0; extra == "dev"
Requires-Dist: numpy==1.26.4; extra == "dev"
Requires-Dist: pyyaml==6.0.1; extra == "dev"
Requires-Dist: flake8==7.3.0; extra == "dev"
Requires-Dist: grpcio-tools>=1.53.2; extra == "dev"
Requires-Dist: twine==6.2.0; extra == "dev"
Requires-Dist: types-attrs>=19.1.0; extra == "dev"
Requires-Dist: types-protobuf==5.29.1.20241207; extra == "dev"
Requires-Dist: types-PyYAML>=6.0.7; extra == "dev"
Requires-Dist: types-requests>=2.27.25; extra == "dev"
Requires-Dist: types-setuptools>=69.0.0.0; extra == "dev"
Requires-Dist: wheel==0.46.2; extra == "dev"
Dynamic: license-file

# Arista CloudVision Python Library

The Arista CloudVision Python library provides access to Arista's CloudVision
APIs for use in Python applications.

## Documentation

API Documentation for this library can be found [here](https://aristanetworks.github.io/cloudvision-python/).

Documentation for CloudVision's Resource APIs can be found [here](https://aristanetworks.github.io/cloudvision-apis).

Documentation for generic access to CloudVision can be found at [CloudVision Connector](#cloudvision-connector).

## Installation

Install via pip:

```sh
pip install --upgrade cloudvision
```

Or from source:

```sh
python setup.py install
```

### Requirements

- CloudVision Resource APIs: Python 3.7+
- CloudVision Connector: Python 3.7+
- Examples: Python 3.7+

## Resource APIs

Cloudvision APIs are state based, resource-oriented APIs modeled in [Protobuf](https://developers.google.com/protocol-buffers) and accessed over [gRPC](https://grpc.io/) using a standardized set of RPC verbs.

CloudVision is a powerful platform that processes and stores tremendous amounts of network data. It knows the topology of the network, device configuration, interface activity and other network events. These APIs allow access to fleet-wide data access and control, forming a management-plane with consistent usage.

For example, consider the following script that gets all existing and then watches for new CloudVision events of critical severity and notifies an administrator when raised and notes it on the event:

```python
import time
import google.protobuf.wrappers_pb2
import grpc
from arista.event.v1 import models, services

# setup credentials as channelCredentials

with grpc.secure_channel("www.arista.io:443", channelCredentials) as channel:
    event_stub = services.EventServiceStub(channel)
    event_annotation_stub = services.EventAnnotationConfigServiceStub(channel)

    event_watch_request = services.EventStreamRequest(
        partial_eq_filter=[models.Event(severity=models.EVENT_SEVERITY_CRITICAL)],
    )
    for resp in event_stub.Subscribe(event_watch_request):
        print(f"Critical event {resp.title.value} raised at {resp.key.timestamp}")
        # send alert here via email, webhook, or incident reporting tool

        # then make a note on the event indicating an alert has been sent
        now_ms = int(time.time() * 1000)
        notes_to_set = {
            now_ms: models.EventNoteConfig(
                note=google.protobuf.wrappers_pb2.StringValue(
                    value="Administrator alerted",
                ),
            ),
        }
        annotation_config = models.EventAnnotationConfig(
            key=resp.key,
            notes=models.EventNotesConfig(
                notes=notes_to_set,
            ),
        )
        event_note_update = services.EventAnnotationConfigSetRequest(value=annotation_config)
        event_annotation_stub.Set(event_note_update)
```

### Async support

Starting from version 1.26.1+ it is possible to use alternative GRPC client based on
[grpclib](https://github.com/vmagamedov/grpclib),that supports pure-python async stubs.
This stubs could be found in `cloudvision.api.arista` module. More specific information and specifications are provided in
[the API documentation](https://aristanetworks.github.io/cloudvision-python/cloudvision.api.arista.html)
While two types of stubs are supported, it is recommended to use ones from `cloudvision.api.arista`,
as they use more idiomatic structure, naming conventions and leverage standard python library
to describe data model.

Example below shows how to retrieve a list of devices:

```python
import asyncio
from cloudvision.api.client import AsyncCVClient
from cloudvision.api.arista.inventory.v1 import DeviceServiceStub, DeviceStreamRequest

async def get_devices():
    client = AsyncCVClient.from_token('<your service account token>', 'your-cvp.io')

    # get channel
    with client as channel:

        # pass it to the stub
        service = DeviceServiceStub(channel)

        # execute one of stub's methods
        async for item in service.get_all(DeviceStreamRequest()):
            print(item)

asyncio.run(get_devices())
```

## CloudVision Connector

CloudVision Connector is a Python implementation of a GRPC client for CloudVision. It takes care
of getting and publishing data and datasets, and also provides utilities for data
representation.

### Getting started

This is a small example advertising a few of the GRPC client capabilities.
This example prints info from all devices streaming into CloudVision.

```python
targetDataset = "analytics"
path = ["DatasetInfo", "Devices"]
# No filtering done on keys, accept all
keys = []
ProtoBufQuery = CreateQuery([(path, keys)], targetDataset)
with GRPCClient("my-cv-host:9900") as client:
     for notifBatch in client.Get([query]):
         for notif in notifBatch["notifications"]:
             # Get timestamp for all update here with notif.Timestamp
             PrettyPrint(notif["updates"])
```

