An open API service indexing awesome lists of open source software.

https://github.com/openfactoryio/openfactory-asset-api

OpenFactory Serving Layer for Assets
https://github.com/openfactoryio/openfactory-asset-api

Last synced: 3 months ago
JSON representation

OpenFactory Serving Layer for Assets

Awesome Lists containing this project

README

          

# OpenFactory-AssetAPI โ€” Serving Layer for Asset Data

[![Dev Container Ready](https://img.shields.io/badge/devcontainer-ready-green?logo=visualstudiocode\&labelColor=2c2c2c)](docs/devcontainer.md) Python Version
![License](https://img.shields.io/github/license/openfactoryio/openfactory-asset-api?style=flat-square) Pre-Release

---

**OpenFactory-AssetAPI** is the core serving layer within the [OpenFactory](https://github.com/Demo-Smart-Factory-Concordia-University/OpenFactory) platform. It provides efficient access to **real-time** and **computed asset data** through:

* ๐Ÿ”Ž **State query endpoints**
* ๐Ÿ“ก **Streaming interfaces**

Its modular, plugin-based architecture supports flexible deployment and grouping strategies, tailored to various industrial environments.

---

## ๐Ÿš€ Quick Start

> This guide assumes deployment on an OpenFactory **Swarm** cluster.

### โœ… Prerequisites

* Python 3.12+
* Docker
* A running OpenFactory Swarm cluster
* (Optional) `jq` for pretty-printing JSON responses

---

### ๐Ÿ”ง 1. Configure Environment

Create a `.env` file or export the following variables:

```env
GROUPING_STRATEGY=workcenter
DEPLOYMENT_PLATFORM=swarm
KSQLDB_URL=http://:8088
KAFKA_BROKER=:9092
```

---

### โ–ถ๏ธ 2. Run

Install the package on a Swarm **manager node** of your OpenFactory cluster:

```bash
pip install -e .
```

Deploy the services:

```bash
manage deploy
```

---

### ๐ŸŒ 3. Interact with the API

Query asset state:

```bash
curl "http://:5555/asset_state?asset_uuid=PROVER3018" | jq
```

Get specific asset data:

```bash
curl "http://:5555/asset_state?asset_uuid=PROVER3018&id=avail" | jq
```

Stream real-time telemetry:

```bash
curl "http://:5555/asset_stream?asset_uuid=PROVER3018"
```

---

## ๐Ÿงฉ Plugin System

The routing layer loads **grouping strategies** and **deployment platforms** dynamically using Python [entry points](https://packaging.python.org/en/latest/specifications/entry-points/) defined in `pyproject.toml`.

This enables:

* ๐Ÿ•น๏ธ Runtime plugin selection via environment variables:

* `GROUPING_STRATEGY`
* `DEPLOYMENT_PLATFORM`
* โž• Easy plugin extension without modifying core code

**Default plugins:**

* Grouping: `workcenter`
* Deployment: `swarm`, `docker`

โ„น๏ธ Docker Deployment Info

When using the docker deployment platform, start the local server manually with:

```bash
manage runserver
```

---

## ๐Ÿ›  Development

### ๐Ÿงช Install for Dev

Install in editable mode with dev tools:

```bash
pip install -e .[dev]
./dev-setup.sh # installs latest openfactory-core
```
> ๐Ÿ”ง For a zero-config local dev environment using Docker and VS Code, see [Development Container Setup](./docs/devcontainer.md)
---

### ๐Ÿ’ป CLI Commands

Use the `manage` command for development tasks:

```bash
manage deploy # deploys services and streams
manage runserver # starts local API server
manage teardown # cleans up services
```

> ๐Ÿ’ก `manage` requires the package to be installed in editable mode.

---

### โœ… Code Quality

Run linting checks with:

```bash
flake8 .
```

---

## โš™๏ธ Configuration

Key environment variables:

| Variable | Description | Default |
| --------------------- | ------------------------------ | ------------ |
| `GROUPING_STRATEGY` | Grouping plugin to load | `workcenter` |
| `DEPLOYMENT_PLATFORM` | Deployment plugin to load | `swarm` |
| `KSQLDB_URL` | ksqlDB endpoint URL | *(None)* |
| `KAFKA_BROKER` | Kafka bootstrap server address | *(None)* |

๐Ÿ“š For full configuration details, refer to:

* [`routing_layer/app/config.py`](routing_layer/app/config.py)
* [Routing Layer README](routing_layer/README.md#๏ธ-environment-configuration)