Skip to main content

Official Python client for Moondream, a fast and efficient vision language model.

Project description

Moondream Python Client Library

Official Python client library for Moondream, a fast multi-function VLM. This client can target Moondream Cloud or run locally via Photon — on NVIDIA GPUs (Linux x86_64 / aarch64 or Windows) or Apple Silicon Macs.

Capabilities

Moondream goes beyond the typical VLM "query" ability to include more visual functions:

Method Description
caption Generate descriptive captions for images
query Ask questions about image content
detect Find bounding boxes around objects in images
point Identify the center location of specified objects
segment Generate an SVG path segmentation mask for objects

Try it out on Moondream's playground.

Installation

pip install moondream

Quick Start

Choose how you want to run Moondream:

  1. Moondream Cloud — Get an API key from the cloud console
  2. Moondream Photon — High-performance local inference engine on NVIDIA GPUs (Linux / Windows) or Apple Silicon Macs (macOS 13+, Python 3.12). Requires an API key.
import moondream as md
from PIL import Image

# Initialize with Moondream Cloud
model = md.vl(api_key="<your-api-key>")

# Or initialize with local inference (Photon — NVIDIA GPU or Apple Silicon)
model = md.vl(api_key="<your-api-key>", local=True)

# Load an image
image = Image.open("path/to/image.jpg")

# Generate a caption
caption = model.caption(image)["caption"]
print("Caption:", caption)

# Ask a question
answer = model.query(image, "What's in this image?")["answer"]
print("Answer:", answer)

# Stream the response
for chunk in model.caption(image, stream=True)["caption"]:
    print(chunk, end="", flush=True)

API Reference

Constructor

model = md.vl(api_key="<your-api-key>")                        # Cloud
model = md.vl(api_key="<your-api-key>", local=True)            # Photon (local: NVIDIA GPU or Apple Silicon)
model = md.vl(api_key="<your-api-key>", model="moondream3-preview/ft_id@step")  # Finetune

Methods

caption(image, length="normal", stream=False)

Generate a caption for an image.

Parameters:

  • imageImage.Image or EncodedImage
  • length"normal", "short", or "long" (default: "normal")
  • streambool (default: False)

Returns: CaptionOutput{"caption": str | Generator}

caption = model.caption(image, length="short")["caption"]

# With streaming
for chunk in model.caption(image, stream=True)["caption"]:
    print(chunk, end="", flush=True)

query(image, question, stream=False)

Ask a question about an image.

Parameters:

  • imageImage.Image or EncodedImage
  • questionstr
  • streambool (default: False)

Returns: QueryOutput{"answer": str | Generator}

answer = model.query(image, "What's in this image?")["answer"]

# With streaming
for chunk in model.query(image, "What's in this image?", stream=True)["answer"]:
    print(chunk, end="", flush=True)

detect(image, object)

Detect specific objects in an image.

Parameters:

  • imageImage.Image or EncodedImage
  • objectstr

Returns: DetectOutput{"objects": List[Region]}

objects = model.detect(image, "car")["objects"]

point(image, object)

Get coordinates of specific objects in an image.

Parameters:

  • imageImage.Image or EncodedImage
  • objectstr

Returns: PointOutput{"points": List[Point]}

points = model.point(image, "person")["points"]

segment(image, object, spatial_refs=None, stream=False)

Segment an object from an image and return an SVG path.

Parameters:

  • imageImage.Image or EncodedImage
  • objectstr
  • spatial_refsList[[x, y] | [x1, y1, x2, y2]] — optional spatial hints (normalized 0-1)
  • streambool (default: False)

Returns:

  • Non-streaming: SegmentOutput{"path": str, "bbox": Region}
  • Streaming: Generator yielding update dicts
result = model.segment(image, "cat")
svg_path = result["path"]
bbox = result["bbox"]  # {"x_min": ..., "y_min": ..., "x_max": ..., "y_max": ...}

# With spatial hint (point)
result = model.segment(image, "cat", spatial_refs=[[0.5, 0.5]])

# With streaming
for update in model.segment(image, "cat", stream=True):
    if "bbox" in update and not update.get("completed"):
        print(f"Bbox: {update['bbox']}")  # Available in first message
    if "chunk" in update:
        print(update["chunk"], end="")  # Coarse path chunks
    if update.get("completed"):
        print(f"Final path: {update['path']}")  # Refined path
        print(f"Final bbox: {update['bbox']}")

encode_image(image)

Pre-encode an image for reuse across multiple calls.

Parameters:

  • imageImage.Image or EncodedImage

Returns: Base64EncodedImage

encoded = model.encode_image(image)

Types

Type Description
Image.Image PIL Image object
EncodedImage Base class for encoded images
Base64EncodedImage Output of encode_image(), subtype of EncodedImage
Region Bounding box with x_min, y_min, x_max, y_max
Point Coordinates with x, y indicating object center
SpatialRef [x, y] point or [x1, y1, x2, y2] bbox, normalized to [0, 1]

Links

Project details


Download files

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

Source Distribution

moondream-1.2.0.tar.gz (103.9 kB view details)

Uploaded Source

Built Distribution

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

moondream-1.2.0-py3-none-any.whl (103.6 kB view details)

Uploaded Python 3

File details

Details for the file moondream-1.2.0.tar.gz.

File metadata

  • Download URL: moondream-1.2.0.tar.gz
  • Upload date:
  • Size: 103.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for moondream-1.2.0.tar.gz
Algorithm Hash digest
SHA256 9f89d80501ba60b04a16ed1ce1de0b562224c688b434a1f3b74840830e6e665c
MD5 bdbb722edfe766f37af211ae9757e387
BLAKE2b-256 2c03f7bd9cd601c6ac5cd2fe0db7821116be9bb39dd5bb4443f8a098041370a6

See more details on using hashes here.

File details

Details for the file moondream-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: moondream-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 103.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for moondream-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 180093cfe97406eb743ae4d765654354b2e398db0b74cd78cd1f691d0ed97289
MD5 5d9fa3fb1179a6925b8f98fe985be6a4
BLAKE2b-256 259625c69ca5e45270007e9e520bffa3319342fe9683066aa2f32abe7daf86eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page