Skip to main content

AIserver

PyPI Python CI License

中文说明

AIserver is a lightweight, local-first Python server for exposing AI inference functions as secure, typed, and concurrency-controlled HTTP APIs.

It is intentionally smaller than a model runtime or distributed serving platform. Bring any Python model or pipeline you already use; AIserver handles request validation, task execution, job status, progress, lifecycle hooks, and conservative network defaults.

Features

  • Turn typed Python functions into documented HTTP endpoints.
  • Run tasks directly or submit in-memory asynchronous jobs.
  • Limit concurrency per task to protect CPU, GPU, and model memory.
  • Report progress from synchronous or asynchronous inference code.
  • Apply per-task timeouts and bounded job history.
  • Load and release models with startup and shutdown hooks.
  • Protect private endpoints with AISERVER_TOKEN.
  • Reject oversized request bodies and bind to localhost by default.
  • Generate OpenAPI documentation automatically at /docs.
  • No telemetry, model downloads, protocol proxy, or request-body logging.

Requirements

  • Python 3.11 or newer
  • Windows, Linux, or macOS

Install

pip install AIserver

Until 0.1.0 is available on PyPI, install the wheel from the GitHub Release or build from source.

Quick start

Create app.py:

from aiserver import AIServer, TaskContext

server = AIServer("demo")


@server.task(concurrency=2, timeout=30)
def classify(text: str, context: TaskContext) -> dict[str, str]:
    context.report(0.5, "running inference")
    return {"label": text.upper()}

Run it:

aiserver run app:server

Open http://127.0.0.1:8000/docs, or call it directly:

curl -X POST http://127.0.0.1:8000/v1/tasks/classify/run \
  -H "Content-Type: application/json" \
  -d '{"text":"hello"}'

Submit the same task as a job:

curl -X POST http://127.0.0.1:8000/v1/tasks/classify/jobs \
  -H "Content-Type: application/json" \
  -d '{"text":"hello"}'

Poll the returned status_url to read progress and the final result.

Lifecycle hooks

Keep large model objects in your application module and initialize them once:

model = None


@server.on_startup
def load_model():
    global model
    model = load_your_model()


@server.on_shutdown
def release_model():
    global model
    model = None

AIserver is deliberately single-process so tasks can share an in-memory model. Its asynchronous job records are not persistent and are lost when the process restarts.

LAN access

The CLI refuses unauthenticated non-loopback binding by default. Set the token in the environment, then start the server:

$env:AISERVER_TOKEN = "use-a-long-random-value"
aiserver run app:server --host 0.0.0.0

Clients can use either header:

Authorization: Bearer <token>
X-API-Key: <token>

Do not pass tokens on the command line or commit them to source control. Use a reverse proxy with TLS before exposing AIserver outside a trusted private network.

Scope

AIserver is not an LLM inference engine, OpenAI/Anthropic protocol gateway, model downloader, distributed scheduler, or hosted control plane. Projects that need those capabilities should use specialized runtimes and platforms.

Historical package notice

Version 0.1.0 is a clean rewrite. It does not preserve the unrelated remote-chat and robot demo APIs from the historical 0.0.x releases. Those releases should not be used.

Development

python -m venv .venv
.venv/Scripts/pip install -e ".[dev]"
ruff check .
pytest
python -m build
python -m twine check dist/*

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiserver-0.1.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiserver-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file aiserver-0.1.0.tar.gz.

File metadata

  • Download URL: aiserver-0.1.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for aiserver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4bb3cb17433eb66e6a6d83900c46a34c44bbf8d28c633d1190a0b79c09a84ec6
MD5 f88a1f76ddc0256f02e4ae385b654987
BLAKE2b-256 797f95578dc07bf7fa5f8918da0f9159c98df98851168b9a3fc38cefd87ab16f

See more details on using hashes here.

File details

Details for the file aiserver-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiserver-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for aiserver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7994d80ca8ae225f8812fbfcb0a76a7550d019c9ccf9bed72f63199ce0a329c3
MD5 a3d312453df475732b042930d0625850
BLAKE2b-256 1be29d4ef0e6fbee960609e5ddb8bc7c3fe14607d2d0e5b56ee637339ccba749

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

0.0.9

1 file

0.0.8

1 file

0.0.6

1 file

0.0.3

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page