Metadata-Version: 2.1
Name: Karabo-proxy
Version: 1.0.4
Summary: Client library for the Karabo WebProxy with sync and async support
Author: costar & degon
License: BSD 3-Clause License
        
        Copyright (c) 2017, European X-Ray Free-Electron Laser Facility GmbH
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        * Redistributions of source code must retain the above copyright notice, this
          list of conditions and the following disclaimer.
        
        * Redistributions in binary form must reproduce the above copyright notice,
          this list of conditions and the following disclaimer in the documentation
          and/or other materials provided with the distribution.
        
        * Neither the name of the copyright holder nor the names of its
          contributors may be used to endorse or promote products derived from
          this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/European-XFEL/karabo_proxy
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiodns
Requires-Dist: aiohttp >=3.9.0
Requires-Dist: requests >=2.28.0
Provides-Extra: test
Requires-Dist: flake8 ; extra == 'test'
Requires-Dist: isort >=5.10.0 ; extra == 'test'
Requires-Dist: pytest >=7.4.0 ; extra == 'test'
Requires-Dist: pytest-asyncio ; extra == 'test'

# Karabo-Proxy

## Overview

The Karabo WebProxy device exposes a web API that allows any HTTP client to
interact with devices in its [Karabo](http://karabo.eu) topic.

This project, **Karabo-Proxy**, provides a convenience Python 3 client library for
interacting with an instance of the Karabo WebProxy device in a (mostly)
HTTP-agnostic way.

Karabo-Proxy offers two client variants, **SyncKaraboProxy** and
**AsyncKaraboProxy**, with a common interface. The first is a synchronous
(blocking) client and the second is an asynchronous (`asyncio`-friendly) client.

Examples of use of both clients in some common scenarios are shown below. For full
details please look at the docstrings available in the library.

## Installation

### From a local clone of the project

```
git clone https://github.com/European-XFEL/karabo_proxy.git
cd karabo_proxy
pip install .
```

### From pypi.org

```
pip install karabo_proxy
````

## How to Use

### Connect to a WebProxy instance

```
from karabo_proxy import SyncKaraboProxy

client = SyncKaraboProxy("http://web_proxy_host:8282")
```

```
from karabo_proxy import AsyncKaraboProxy

async_client = AsyncKaraboProxy("http://web_proxy_host:8282")
```

### Retrieve the Topology of the Karabo Topic

The topology is returned as an object of type `karabo_proxy.data.topology.TopologyInfo`.

```
topology = client.get_topology()
```

```
topology = await async_client.get_topology()
```

### Get the Configuration of a Device

The device configuration is returned as a dictionary where the identifiers of the device
properties are the keys and the values are of type `karabo_proxy.data.device_config.PropertyInfo` (property value with timing information).

```
config = client.get_device_configuration("DEVICE_ID")
```

```
config = await async_client.get_device_configuration("DEVICE_ID")
```

### Configure a Device

This operation is only allowed on devices that are in the list of `reconfigurableDevices`
of the connected WebProxy. The properties being set should be provided as a dictionary
where the key is the property identifier and the value is the value to be set for the property.

```
result = client.set_device_configuration("DEVICE_ID",
                                         "{"prop_1": 3.14159,
                                         "prop_2": "activating ..." })
```

```
result = await async_client.set_device_configuration("DEVICE_ID",
                                                     "{"prop_1": 3.14159,
                                                     "prop_2": "activating ..." })
```

`result` will be an object with two attributes: `success` (bool) and `reason` (str).
`reason` is empty for successful operations. Otherwise (`success == False`), it
contains an error message detailing what went wrong.

### Execute a Device Slot

Slot execution requires the specified device to be in the list of `reconfigurableDevices`
of the connected WebProxy. Its return value has the same type and semantics of the
return value of the `set_device_configuration` operation.

```
result = client.execute_slot("DEVICE_ID",
                             "slot_start", {"param1": "NOW", "param2": 30})
```

```
result = await async_client.execute_slot("DEVICE_ID",
                                         "slot_start",
                                         {"param1": "NOW", "param2": 30})
```

The slot parameters, if any, should be passed as a dictionary with the parameter
name as the key and the value as the value.

## Contact

For questions, please contact opensource@xfel.eu.

## License and Contributing

This software is released by the European XFEL GmbH as is and without any warranty under the GPLv3 license. If you have questions on contributing to the project, please get in touch at opensource@xfel.eu.
