Metadata-Version: 2.4
Name: hyped-extensions-serve
Version: 0.1.0a0
Summary: Serve hyped data flows as REST APIs
Author: open-hyped
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: hyped>=0.1.0
Requires-Dist: fastapi>=0.110.2
Requires-Dist: uvicorn[standard]>=0.29.0
Provides-Extra: linting
Requires-Dist: pre-commit; extra == "linting"
Provides-Extra: tests
Requires-Dist: pytest; extra == "tests"
Requires-Dist: pytest-cov; extra == "tests"
Requires-Dist: httpx>=0.28.1; extra == "tests"
Provides-Extra: docs
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: furo; extra == "docs"

# Hyped Serve Extension

[![Tests](https://github.com/open-hyped/hyped-extensions-serve/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/open-hyped/hyped-extensions-serve/actions/workflows/tests.yml)
[![Linting](https://github.com/open-hyped/hyped-extensions-serve/actions/workflows/linting.yml/badge.svg?branch=main)](https://github.com/open-hyped/hyped-extensions-serve/actions/workflows/linting.yml)
[![Coverage Status](https://coveralls.io/repos/github/open-hyped/hyped-extensions-serve/badge.svg?branch=main)](https://coveralls.io/github/open-hyped/hyped-extensions-serve?branch=main)
[![PyPi version](https://badgen.net/pypi/v/hyped-serve/)](https://pypi.org/project/hyped-serve)
[![PyPi license](https://badgen.net/pypi/license/hyped-serve/)](https://pypi.org/project/hyped-serve/)

Serve hyped data flows as REST APIs

## Installation

You can install the add-on directly from PyPI using pip:

```bash
pip install hyped-extensions-serve
```

## Getting Started

Hyped serve leverages the power of [FastAPI](https://fastapi.tiangolo.com) to create a robust serving environment.

To get started, simply define your data pipeline and its expected input features in a Python script, and then serve it using `hyped-extensions-serve`.

Here's a basic example:

```python
# app.py
from hyped import DataFlow
from hyped.typing import Mapping, Int
from hyped.extensions.serve import HypedAPI

# Define your input schema
class Inputs(Mapping):
    x: Int

# Define your data flow
flow = DataFlow[Inputs]()
flow = flow.build(collect={"y": flow.source["x"] * 2})

# Create the app to be served
app = HypedAPI().serve_flow(flow, prefix="/")
```

Once you've defined your app, you can serve it using uvicorn:

```bash
uvicorn app:app --host 0.0.0.0 --port 80
```
This will start the server, allowing you to interact with your data pipeline via HTTP requests.

## Endpoints

The Hyped Serve API provides the following endpoints for interacting with your data pipeline:

| Endpoint   | Method | Description                                                                                            |
|------------|--------|--------------------------------------------------------------------------------------------------------|
| /health    | GET    | Simple health check always returns "ok" and code 200.                                                  |
| /readiness     | GET    | Simple readiness check always returns "ok" and code 200.                                           |
| \<prefix\>/readiness | GET    | Readiness check to determine if the flow is ready to receive requests.                               |
| \<prefix\>/apply | POST   | Apply the data flow to a single example. Expects a single example in JSON format. |
| \<prefix\>/batch | POST   | Apply the data flow to a batch of data. Expects a list of examples.                   |

Additionally, a Swagger UI API documentation is available at `/docs`.

## Serving multiple Data Pipes

The serving environment also supports serving multiple data pipes simultaneously. You can configure this by providing multiple data pipes and their respective features.

```python
# app.py

app = (
    HypedAPI()
    .serve_flow(flowA, prefix="/A")
    .serve_flow(flowB, prefix="/B")
)
```

This example demonstrates serving two different data pipes (pipe_one and pipe_two) with their corresponding features, each accessible via different prefixes (/one and /two).

## Running Tests

Hyped Serve includes a suite of tests to ensure its functionality. You can run these tests using pytest:

```bash
pytest tests
```

Ensure that you have pytest installed in your environment. You can install it via pip:

```bash
pip install pytest
```

Running the tests will execute various test cases to validate the behavior of Hyped Serve.

## License

tbd
