Metadata-Version: 2.1
Name: jamspy
Version: 0.4.0
Summary: A HTTP & gRPC client for J.A.M.S - Just Another Model Server in Python
Author: gagansingh894
Project-URL: Homepage, https://github.com/gagansingh894/jams-rs/tree/main/clients/python/jams
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic ==2.6
Requires-Dist: requests ==2.32.3
Requires-Dist: grpcio ==1.67.0
Requires-Dist: protobuf >=3.20.3
Requires-Dist: grpcio-tools ==1.65.5
Requires-Dist: ruff ==0.6.9
Requires-Dist: mypy ==1.11.1
Requires-Dist: types-requests ==2.32.0.20240914
Requires-Dist: types-protobuf ==5.28.0.20240924
Requires-Dist: pytest ==8.0.0
Requires-Dist: pytest-asyncio ==0.23.8
Requires-Dist: nox ==2024.4.15
Requires-Dist: catboost ==1.2.3
Requires-Dist: lightgbm ==4.0.0
Requires-Dist: torch ==2.2.0
Requires-Dist: xgboost ==2.0.3
Requires-Dist: numpy ==1.26.0
Requires-Dist: httpx ==0.26.0
Provides-Extra: dev
Requires-Dist: check-manifest ; extra == 'dev'

# J.A.M.S Python Client


A HTTP & gRPC client for `J.A.M.S - Just Another Model Server`

## Installation
```
pip install jamspy
```

## Usage

Start `J.A.M.S` by following the instructions [here](https://github.com/gagansingh894/jams-rs?tab=readme-ov-file#docker-setup)

### HTTP

```
import asyncio
import json
from jamspy.client.http import Client

# Initialize the async client
client = Client('0.0.0.0:3000')

async def main():
    # Perform a health check
    await client.health_check()

    # Define model and input data for prediction
    model_name = "titanic_model"
    model_input = json.dumps({
        "pclass": ["1", "3"],
        "sex": ["male", "female"],
        "age": [22.0, 23.79929292929293],
        "sibsp": ["0", "1"],
        "parch": ["0", "0"],
        "fare": [151.55, 14.4542],
        "embarked": ["S", "C"],
        "class": ["First", "Third"],
        "who": ["man", "woman"],
        "adult_male": ["True", "False"],
        "deck": ["Unknown", "Unknown"],
        "embark_town": ["Southampton", "Cherbourg"],
        "alone": ["True", "False"],
    })

    # Perform a prediction and await the response
    prediction = await client.predict(model_name=model_name, model_input=model_input)
    print(prediction.values)  # Use predictions

    # Add a model (model name format: <MODEL FRAMEWORK>-<MODEL_NAME>)
    await client.add_model(model_name='tensorflow-my_awesome_penguin_model')

    # Update the model
    await client.update_model(model_name='my_awesome_penguin_model')

    # Delete the model
    await client.delete_model(model_name='my_awesome_penguin_model')

    # Fetch the list of models and await the response
    models = await client.get_models()
    print(models)

# Run the main function as an async entry point
asyncio.run(main())

```

### gRPC

```
import json
import asyncio
from jamspy.client.grpc import Client

async def main():
    # Initialize the asynchronous client
    client = Client('0.0.0.0:4000')

    # Health check
    await client.health_check()

    # Define model and input data for prediction
    model_name = "titanic_model"
    model_input = json.dumps({
        "pclass": ["1", "3"],
        "sex": ["male", "female"],
        "age": [22.0, 23.79929292929293],
        "sibsp": ["0", "1"],
        "parch": ["0", "0"],
        "fare": [151.55, 14.4542],
        "embarked": ["S", "C"],
        "class": ["First", "Third"],
        "who": ["man", "woman"],
        "adult_male": ["True", "False"],
        "deck": ["Unknown", "Unknown"],
        "embark_town": ["Southampton", "Cherbourg"],
        "alone": ["True", "False"],
    })

    # Predict and await the response
    prediction = await client.predict(model_name=model_name, model_input=model_input)
    print(prediction.values)  # Use predictions

    # Add model
    await client.add_model(model_name='tensorflow-my_awesome_penguin_model') # <MODEL FRAMEWORK>-<MODEL_NAME>

    # Update model
    await client.update_model(model_name='my_awesome_penguin_model')

    # Delete model
    await client.delete_model(model_name='my_awesome_penguin_model')

    # Get models and await the response
    models = await client.get_models()
    print(models)

# Run the main function asynchronously
asyncio.run(main())
```
