Skip to main content

Python/Mojo interface for Google Gemma 3

Project description

🔥 MoGemma

Python/Mojo interface for Google Gemma 3.

Features

  • Embeddings — Dense vector embeddings via a pure Mojo backend.
  • Text generation — Synchronous and async streaming with configurable sampling.
  • Multimodal Vision — Native support for Gemma 3 Vision models with zero-copy image processing.
  • Google Cloud Storage — Automatic model download from Google's gemma-data bucket.
  • OpenTelemetry — Optional tracing instrumentation.

Installation

Recommended for most users:

pip install 'mogemma[llm]'

This enables the text generation and embedding examples shown below.

For multimodal generation with automatic image decoding from str, Path, or raw bytes inputs:

pip install 'mogemma[vision]'

Base package only:

pip install mogemma

Use the base package if you're already preparing tokens or image arrays yourself.

Quick Start

Text Generation

The default getting-started path is mogemma[llm].

from mogemma import SyncGemmaModel

model = SyncGemmaModel()
print(model.generate("Write a haiku about a robot discovering coffee:"))

Multimodal Vision

MoGemma supports Gemma 3 multimodal vision models.

  • Install mogemma[vision] to pass image file paths or raw image bytes directly.
from mogemma import SyncGemmaModel

# Initialize a vision-capable model
model = SyncGemmaModel("gemma3-4b-it")

response = model.generate("Describe this image in detail:", images=["input.jpg"])
print(response)

Async Streaming

import asyncio
from mogemma import AsyncGemmaModel

async def main():
    model = AsyncGemmaModel()
    async for token in model.generate_stream("Once upon a time"):
        print(token, end="", flush=True)

asyncio.run(main())

Embeddings

Generate dense vector embeddings natively through Mojo's optimized batched kernel operations. Pass a single string or a list of strings to process them in parallel.

from mogemma import EmbeddingModel

model = EmbeddingModel()
embeddings = model.embed(["Hello, world!", "Mojo runs Gemma inference."])
print(embeddings.shape)  # (2, 768)

Selecting a Model Variant

All model classes default to gemma3-270m-it. Pass a model ID to use a different variant:

model = SyncGemmaModel("gemma3-1b-it")

For full control over sampling parameters, pass a GenerationConfig:

from mogemma import GenerationConfig, SyncGemmaModel

config = GenerationConfig(model_path="gemma3-1b-it", temperature=0.7)
model = SyncGemmaModel(config)

Device Selection

GenerationConfig and EmbeddingConfig accept:

  • device="cpu"
  • device="gpu"
  • device="gpu:0" (or other index)

Device handling is deterministic:

  • device="cpu" always runs on CPU
  • explicit GPU requests never silently fall back to CPU
  • unavailable GPU requests raise an explicit error

Current runtime status:

  • cpu and gpu are executable backends today
  • gpu / gpu:N execute via a mathematically verified runtime polyfill
from mogemma import EmbeddingConfig, EmbeddingModel, GenerationConfig, SyncGemmaModel

generation = SyncGemmaModel(
    GenerationConfig(
        model_path="gemma3-1b-it",
        device="cpu",
    )
)

embeddings = EmbeddingModel(
    EmbeddingConfig(
        model_path="gemma3-1b-it",
        device="cpu",
    )
)

Runtime Requirements

MoGemma leverages the latest Mojo features for maximum performance.

  • Mojo Nightly: Version 0.26.3.0.dev or later is required for building from source.
  • Python: 3.10+

Development & Architecture

Architecture Specific Builds

MoGemma automatically optimizes its Mojo core for your specific CPU architecture during the build process.

  • x86_64: Uses --target-cpu x86-64-v3 for optimized vector instructions.
  • aarch64: Uses native ARM optimizations.

Local Development

To build the Mojo extension locally:

make build

License

MIT

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

mogemma-0.3.0.tar.gz (208.0 kB view details)

Uploaded Source

Built Distributions

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

mogemma-0.3.0-cp313-cp313-manylinux_2_34_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

mogemma-0.3.0-cp313-cp313-manylinux_2_34_aarch64.whl (17.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

mogemma-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (811.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mogemma-0.3.0-cp313-cp313-macosx_10_13_x86_64.whl (811.5 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

mogemma-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mogemma-0.3.0-cp312-cp312-manylinux_2_34_aarch64.whl (17.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

mogemma-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (811.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mogemma-0.3.0-cp312-cp312-macosx_10_13_x86_64.whl (811.5 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

mogemma-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

mogemma-0.3.0-cp311-cp311-manylinux_2_34_aarch64.whl (17.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

mogemma-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (811.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mogemma-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl (811.5 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

mogemma-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl (19.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

mogemma-0.3.0-cp310-cp310-manylinux_2_34_aarch64.whl (17.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

mogemma-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (811.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

mogemma-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl (811.5 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file mogemma-0.3.0.tar.gz.

File metadata

  • Download URL: mogemma-0.3.0.tar.gz
  • Upload date:
  • Size: 208.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mogemma-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3a2a1ab6aeaac2e446aa439061c5d225ea519e82a3ce430b4365895e7b90bb05
MD5 48dff21559dfe4ce28555935ea74c24d
BLAKE2b-256 834953bcde0d997099d0dfee0dd2c1eff0b5d049176f195e917e28222b12c998

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0.tar.gz:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 64d740aa6d9fc16c14985caaec7040686ce1057b8ac78a0fa15542088f2fd303
MD5 f3663514b9ee83f7a6c208c067cf010c
BLAKE2b-256 bfe0a0f49ae1147d0041fa9df1296c9744c37fceebf5b502c9a35c6257a59554

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 879dca74283af29a5541e721558bfe4af21143fdd420687a80989b0e5a958e47
MD5 62fc54754b5f2d3aa21ebaa186f920ad
BLAKE2b-256 edebf08091775fcde6136ad7f0fe2458ce3570a0711e2b06288bebbe903da49a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp313-cp313-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f74501a77325598c9c5a385c7aec2217189c664cfeb3585adda689d1be933b3
MD5 4ca7ffe65139059d2d8eab50a319b400
BLAKE2b-256 fd0b8a19435eefa09c597852d0b059206b8596f6ee291b423c37362ba1be4881

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 bf539243e685ceb001c24d56a7b5292d8384f034260a7407384fe559dedbd6b2
MD5 ccf008f3c796bb7dde448fc3baa4dc9d
BLAKE2b-256 1ca187519dcfe0d903976e7358d76f5edf254eb6ad8bb909a6678f37802f5d85

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 03168a8ecd23ccdf60c2a61b87519983677d4c899ba2e3018e37c35cacc13c76
MD5 61078c162f465296fdae285e24e0fbc5
BLAKE2b-256 ef9d82b94ae23baccb19078f17358bf808d84a0767771c7d6f7ffca01051a847

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f835ddef169299d5a1df05fcc961efd1376469469027ec9d51ead008232b9278
MD5 5f98191c79544cc47cbd60b1a1d38aa6
BLAKE2b-256 8d93e51e6aa1b9948abe3e2aa7a87bc203a5ca89d712cc7cdc362648cace2825

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp312-cp312-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6532c167061ae56c20ec5d29ff713b7687a86a42e15c71f7b0c811c41dbf0a6c
MD5 9cff5940d83545e6eec42d6c97cdd00e
BLAKE2b-256 7c52c458aa8a76316bba6e4d866b48ce0b42a71b0f2a50048c6a20cfe2667f58

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d9355aee7b867a10345c7b3cb34e5864b742b4d99a9cf5fced33aac5ab46b1d2
MD5 92dd53382a1fada31c362f752d7afb4c
BLAKE2b-256 992f8e1efd25e84ece2262079beb59f6278c563e8514c8577385ed83e8fa5ad1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b2dea9db05bf942eeae494a3486e8fe1a1d875ede4c53d813e1eabdd94cba891
MD5 32567a3ea36f95a00e9fc8b0f5357605
BLAKE2b-256 9607b41fbc0c664fbf50d22496ca41f462147bde080a3115a86694bf30cb8797

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ea027cb994800ce882f306030decf8f248bb74a417b1055bd5bbf00d6d52a503
MD5 3c0e88a4b3633bd1df792eb67a849398
BLAKE2b-256 2a68cdd8c1ff052ae2c5d5f916eb56cbbed259c865863a3631a27dd421398c4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp311-cp311-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 87a26e8a91cda93e6861257c03f2c3f0bc0494319d4a112a265899f8ed899964
MD5 fa0f942c2bcb4f5d30cc24a65f7dc3f0
BLAKE2b-256 7fdcc629f5cce80b0a9d6427595578d1c622962cd74206233811659d8485813f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 24d9fa5723a084e1f4b9346188d2e9e9ff2356f0feb1f8ee7b549caf4b574895
MD5 d3df1ba9053a9db6f429139e138b4858
BLAKE2b-256 e5d4d99fb8ca868012ee8adaafc6b072190d9f2a0cb1733e8eb6fc7468d88ce4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bbe0eb24dc7f7faae70e1d781aeb82987865b085403e59512eac9eac03c81271
MD5 e8f17e3dee8a511c8da88cf1faa2e600
BLAKE2b-256 9cddae6585eafb00c6e65d6e50b16c4ba0f567a4ed6b27dc903589ba1759950c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 46a51faeabc56e003adc99276cea5e199369b6dc2ae3dc81a834778b5ae97b2e
MD5 215525f6ce0c1e39a15f066ad36c1e50
BLAKE2b-256 3f7bec5357eb7df8fd0df4d68b818e70a661e26aae11391790110445642df52a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp310-cp310-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34dccd18beb56e8fced8390b3990030728d6a8cb1a21ff5a7e4c7651383f5184
MD5 519afab315409431e02f25d6e6d27f89
BLAKE2b-256 cb440e21985c6d46243904d3abf65cd3c4442aebd65b7965b12cdd327b8fc8a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mogemma-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mogemma-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8c297563162ddd2d6eec67f18233a55c48c0930a47c3cec4ef923654a6f07048
MD5 11e760bc797026f32ce5cfbfc724e9f0
BLAKE2b-256 148106773310eee2c89a1394fa798aa7c24bdd4429c79e2c3a50ff7e600c0708

See more details on using hashes here.

Provenance

The following attestation bundles were made for mogemma-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: publish.yml on cofin/mogemma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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