Metadata-Version: 2.4
Name: inferencesh
Version: 0.2.9
Summary: inference.sh Python SDK
Author: Inference Shell Inc.
Author-email: "Inference Shell Inc." <hello@inference.sh>
Project-URL: Homepage, https://github.com/inference-sh/sdk
Project-URL: Bug Tracker, https://github.com/inference-sh/sdk/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0.0
Requires-Dist: tqdm>=4.67.0
Provides-Extra: test
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Dynamic: author
Dynamic: license-file
Dynamic: requires-python

# inference.sh CLI

Helper package for inference.sh Python applications.

## Installation

```bash
pip install infsh
```

## File Handling

The `File` class provides a standardized way to handle files in the inference.sh ecosystem:

```python
from infsh import File

# Basic file creation
file = File(path="/path/to/file.png")

# File with explicit metadata
file = File(
    path="/path/to/file.png",
    content_type="image/png",
    filename="custom_name.png",
    size=1024  # in bytes
)

# Create from path (automatically populates metadata)
file = File.from_path("/path/to/file.png")

# Check if file exists
exists = file.exists()

# Access file metadata
print(file.content_type)  # automatically detected if not specified
print(file.size)       # file size in bytes
print(file.filename)   # basename of the file

# Refresh metadata (useful if file has changed)
file.refresh_metadata()
```

The `File` class automatically handles:
- MIME type detection
- File size calculation
- Filename extraction from path
- File existence checking

## Creating an App

To create an inference app, inherit from `BaseApp` and define your input/output types:

```python
from infsh import BaseApp, BaseAppInput, BaseAppOutput, File

class AppInput(BaseAppInput):
    image: str  # URL or file path to image
    mask: str   # URL or file path to mask

class AppOutput(BaseAppOutput):
    image: File

class MyApp(BaseApp):
    async def setup(self):
        # Initialize your model here
        pass

    async def run(self, app_input: AppInput) -> AppOutput:
        # Process input and return output
        result_path = "/tmp/result.png"
        return AppOutput(image=File(path=result_path))

    async def unload(self):
        # Clean up resources
        pass
```

The app lifecycle has three main methods:
- `setup()`: Called when the app starts, use it to initialize models
- `run()`: Called for each inference request
- `unload()`: Called when shutting down, use it to free resources
