Skip to main content

server

An HTTP server designed for AI

Quickstart

Install the Banana server package

pip3 install banana-server

Create a python file called main.py with this:

from banana_server import Banana

app = Banana("server")

@app.init
def init():
    model = "my pytorch model"
    app.optimize(model)

    return app.set_cache({
        "model": model,
        "hello": "world"
    })

@app.handler
def handler(cache, json_in) -> dict:
    print("cache:", cache)
    print("json_in:", json_in)
    return {"json": "out"}

app.serve()

Run it with

python3 main.py

Test the running server with

curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' http://localhost:8000

Documentation

banana_server.Banana

from banana_server import Banana

app = Banana("server")

This instantiates your HTTP app, similar to popular frameworks like Flask

This HTTP server is production-ready out of the box.

@app.init

@app.init
def init():
    model = "my pytorch model"
    app.optimize(model)

    return app.set_cache({
        "model": model,
        "hello": "world"
    })

The @app.init decorated function runs once on server startup, and is used to load any reuseable, heavy objects such as:

  • Your AI model, loaded to GPU
  • Tokenizers
  • Precalculated embeddings

Once initialized, you must save those variables to the cache with app.set_cache({}) so they can be referenced later.

There may only be one @app.init function.

@app.handler

@app.handler
def handler(cache, json_in) -> dict:
    print("cache:", cache)
    print("json_in:", json_in)
    return {"json": "out"}

The @app.handler decorated function runs for every http call, and is used to run inference or training workloads against your model(s).

Arg Type Description
cache dict The app's cache, set with set_cache()
json_in dict The json body of the input call. If using the Banana client SDK, this is the same as model_inputs
Return Val Type Description
json_out dict The json body to return to the client. If using the Banana client SDK, this is the same as model_outputs

There may only be one @app.handler function.

app.set_cache()

app.set_cache({})

app.set_cache saves the input dictionary to the app's cache, for reuse in future calls. It may be used in both the @app.init and @app.handler functions.

app.set_cache overwrites any preexisting cache.

app.get_cache()

cache = app.get_cache()

app.get_cache fetches the dictionary to the app's cache. This value is automatically provided for you as the cache argument in the @app.handler function.

app.optimize(model)

model # some pytorch model
app.optimize(model)

app.optimize is a feature specific to users hosting on Banana's serverless GPU infrastructure. It is run during buildtime rather than runtime, and is used to locate the model(s) to be targeted for Banana's Fastboot optimization.

Multiple models may be optimized. Only Pytorch models are currently supported.

Metadata

Release files for banana-server 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for banana-server 0.0.1
File Size Uploaded Provenance
banana_server-0.0.1.tar.gz 7.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for banana-server 0.0.1
File Interpreter ABI Platform
banana_server-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / banana_server-0.0.1.tar.gz

Download URL banana_server-0.0.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1d62dc83ccbe890a54714d8adec49b2523d36dc43e60e1f60690328134baef5b
BLAKE2b-256 checksum
How to use checksums
dda84d1f5b2301b4c5af841af2afc54a8abc52e5f5dacfea64cbe3b30224a587
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / banana_server-0.0.1-py3-none-any.whl

Download URL banana_server-0.0.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9188af5d1f56c4f7caaebc40a9a7ea90b8ea7ea052aec9b977d7468fe0a2b12f
BLAKE2b-256 checksum
How to use checksums
b7dc145db7bf4d680e65b6abd395403609af5cf948a150582e48c0ccdf1a1aff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Security for banana-server 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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