Blade AI Fabric SDK + CLI — run Python functions on Blade's GPU fleet.
pip install bladekit==4.25.0 Copy PIP instructions
Run Python functions on the GPU fleet, from your laptop.
Distribution bladekit, import bladekit, command blade (bladekit is installed too, as an alias of the same command). Python ≥ 3.10.
pip install bladekit Also served, with the forge-shadow compatibility package, by the branded index https://console.blade.sh/sdk/ (docs/INSTALL.md in the source repository).
An @app.cls() class is the stateful counterpart of @app.function: it is instantiated once per container and its methods (marked with @app.method()) reuse that instance across calls. Three decorators run code at defined moments in the container's life:
Within each kind, hooks run in definition order; across kinds the order is always build → enter → (calls) → exit.
@app.cls(gpu="RTX-A4500", image="fabric/torch") class Embedder: MODEL = "BAAI/bge-small-en-v1.5" @bladekit.build() def fetch_weights(self): # once at build time (fallback: per container) from huggingface_hub import snapshot_download snapshot_download(self.MODEL) @bladekit.enter() def load(self): # once per container from sentence_transformers import SentenceTransformer self.model = SentenceTransformer(self.MODEL, device="cuda") @app.method() def embed(self, texts): return self.model.encode(texts).tolist() @bladekit.exit() def flush(self): # once at teardown, best-effort print("shutting down") Embedder().embed.remote(["hello", "world"]) Parametrized classes bladekit.parameter() turns one @app.cls definition into many independent instances, one per distinct set of parameter values — the equivalent of modal.parameter. Declare parameters as typed class attributes; a parametrized class defines no __init__ (the values are set for you). Each distinct value set gets its own run and its own container pool, and the bound values travel with every call so AI Fabric routes it to the matching container.
fn.starmap(iterable, ...) — like map, but each element is a tuple splatted as positional args: (a, b) → f(a, b).
fn.spawn_map(iterable, ...) — spawn + map: fire the whole fan-out and return a MapHandle immediately, without blocking on results. The batch is created, all inputs are pushed, and it is finalized server-side; you then poll it at your leisure. fn.spawn_starmap(iterable, ...) is the tuple-splatting variant.
handle = classify.spawn_map(urls) # returns at once — nothing awaited ... # do other work; the fleet churns for label in handle.results(): # collect later (order/return_exceptions here) ... print(handle.status()) # inspect progress handle.cancel() # stop the batch The batch is durable server-side, so a handle survives a client disconnect — re-attach from another process with blade map resume . map() blocks and streams; spawn_map() hands you the handle and gets out of the way.
Contract: positional args are transposed by position and keyword args by name, so every call in a batch must share the same call shape; the function must return a list of exactly len(batch) results (else the whole batch fails with BATCH_RESULT_LENGTH_MISMATCH). If the function raises, every call in the batch receives that exception.
bladekit.CloudBucketMount mounts an external object-store bucket you own (S3 / GCS / R2 / MinIO / Scaleway — anything speaking the S3 API) as a filesystem path inside a function or deployed replica. Unlike bladekit.Volume (an AI Fabric-managed network volume with generations and commit()), a bucket mount is a live view of your bucket — AI Fabric only mounts it, it never stores the objects. The runner FUSE-mounts each bucket at container start and unmounts it on teardown.
Pass it in the same volumes= map as a Volume, keyed by mount path:
Store the credentials first with blade secret create aws-credentials AWS_ACCESS_KEY_ID=… AWS_SECRET_ACCESS_KEY=…. At most 8 bucket mounts per function; mount paths share the volume namespace (absolute, unique, outside reserved paths).
blade setup (browser token flow) and blade token set both write ~/.blade/config.toml. FABRIC_API_URL / FABRIC_TOKEN environment variables take precedence; FABRIC_CONFIG points the CLI at another file. blade token show says where each value came from.
blade token set never accepts the token as a positional argument — that would leak it into ps aux, shell history and process monitors. Pass it on stdin (echo "$TOK" | blade token set) or name the variable (--from-env FABRIC_TOKEN).
Inside a container, read the platform's variables under their FABRIC_* names (FABRIC_SERVER_PORT, FABRIC_VOLUMES, FABRIC_PREEMPT_GRACE_SECONDS, FABRIC_MAX_SESSION_SECONDS, FABRIC_TURN_URL / FABRIC_TURNS_URL / FABRIC_TURN_SECRET). FABRIC_* and FORGE_* are reserved: Image.env() rejects both prefixes.
The SDK used to be forge-shadow (import forge, command forge). Nothing an existing user does breaks on upgrade; the old names are deprecated and keep working for a transition period (see "Removal" below).
Removal. The deprecated names (forge import and command, forge-shadow, ForgeError, FORGE_* fallback, ~/.forge migration, forge/ alias rewrite) are kept for a transition period whose end is not decided yet; they are removed in a future major release, announced in the changelog.
Bundling tars the script's directory. Add a .forgeignore to exclude paths; it uses exactly the .gitignore syntax and matching rules (* never crosses /, a leading or middle / anchors at the bundle root, a trailing / matches directories only, ** spans directories, ! re-includes). .git, .venv, __pycache__ are always excluded.
Image.from_dockerfile(context_dir=...) filters its build context with a .dockerignore at the context root instead, matched exactly like docker build (patterns are relative to the context root, so *.py only matches top-level files; use **/*.py for any depth). ! is not supported there yet.
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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.
None of the files in this release were uploaded with provenance metadata.
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.




