Metadata-Version: 2.4
Name: psServerWrapper
Version: 2.0.1
Summary: Utilities to run and manage a FastAPI/uvicorn server
Author-email: Anders Schou Simonsen <andersschou.simonsen@alfalaval.com>
License-Expression: MIT
Requires-Python: >=3.15
Description-Content-Type: text/markdown
Requires-Dist: fastapi>=0.160.0
Requires-Dist: uvicorn>=0.54.0

To publish:

```bash
uv run python -m build
uv run twine upload dist/*
```

To install:

```bash
uv add psServerWrapper
```

To update to a newer version after upload during development:
```
uv remove psServerWrapper
uv cache clear psServerWrapper
uv add psServerWrapper
```

To use:

```python
import uvicorn
import psServerWrapper
from fastapi import FastAPI, Request

app = FastAPI()

@app.post("/myEndpoint")
async def myEndpoint(request: Request):
    print("myEndpoint")
    res = {"success": True, "message": "Hi there"}
    return res


server: uvicorn.Server | None = None
psServerWrapper.register_shutdown_endpoint(app, lambda: server)
if __name__ == "__main__":
    def set_server(s: uvicorn.Server) -> None:
        global server
        server = s
    psServerWrapper.run(app, set_server)
```

Run your script with optional arguments:

```bash
python my_server.py --port 8000 --label dev --dt 1000 --debug false
```

## CLI Arguments

- `--port`: Port to bind to. Use `0` to auto-select a free port.
- `--label`: Label included in the status filename.
- `--dt`: Status write interval in milliseconds.
- `--tShutdown`: If no requests are being made to the api for tShutdown[ms] the server will shut down
- `--debug`: Enables uvicorn reload behavior intended for local development.
