Skip to main content

Simple Wrapper For The Gemini AI API

This module is designed for asynchronous usage and provides a simple interface to the Google Gemini API.

It also provides a command-line interface for interactive usage.

NOTICE

Images are not tested and may not work as expected.

Installation

pip install -U gemnine

Usage

Command Line

Configuration

gemnine requires a model and an API key to be set.

You can use config file, command parameters or interactive input to set these values.

By default, gemnine will look for files named config.json and session.json in the user config and cache directory.

gemnine -c /path/to/config.json  # Use a config file
gemnine -m "models/gemini-pro"  # Set model, input API key interactively
gemnine -l  # list available models

Parameters

  • -c, --config: Path to a JSON file
  • -m, --model: Model name
  • -s, --session: Session history file
  • -V, --version: Show version

Precedence: Interactive input > Command parameters > Config file

Interactive Mode

This mode mimics a chat interface. You can type your message and get a response.

Commands are started with a / and are case-sensitive.

  • /exit: Exit the program
  • /save <path>: Save the session history to a file
  • /load: Load a session history from a file
  • /rollback <step>: Rollback to the previous state
  • /clear: Clear the session history
  • /role: Switch role
  • /model: Switch model
  • /help: Show help

To embed an image, insert #image(<url>) in your message. Use double # to escape embedding.

await bot.send("""
What are these?
#image(https://example.com/image.png)
#image(file:///path/to/image.png)
#image(base64://<base64-encoded-image>)
""")

All URLs will be downloaded and embedded as base64-encoded images.

API

import asyncio
import gemnine

bot = gemnine.Bot(model="models/gemini-pro", api_key="your-api-key")

async def main():
    response = await bot.send("Hello, how are you?")
    print(response)

    async for r in bot.stream("I'm fine, thank you."):
        print(r, end='')
    
    # `Bot` instance it self doesn't track the session history
    # To keep track of the session history, use `Session` instance
    sess = bot.new_session()

    print(await sess.send("Hello, how are you?"))

    async for r in sess.stream("What was my last question?"):
        print(r, end='')

asyncio.run(main())

Save and load session history

Session and Bot use pydantic models under the hood. You can save and load the session history using model_dump_json and model_validate_json or pass arguments to new_session methods.

import json
from pathlib import Path
sess_path = Path("session.json")

sess = bot.new_session()

data = sess.model_dump_json()

sess_path.write_text(data)

sess = bot.new_session(**json.loads(sess_path.read_text()))

Metadata

Release files for gemnine 0.1.13

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

Source distribution (sdist)

Source distribution for gemnine 0.1.13
File Size Uploaded Provenance Actions
gemnine-0.1.13.tar.gz 12.5 kB Without provenance Details for gemnine-0.1.13.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gemnine 0.1.13
File Interpreter ABI Platform Actions
gemnine-0.1.13-py3-none-any.whl Python 3 none any Details for gemnine-0.1.13-py3-none-any.whl

Total release size: 24.3 kB

Release files / gemnine-0.1.13.tar.gz

Download URL gemnine-0.1.13.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
76ca9cd008cc3a3a6a383ba21b51557a818870fc4ab0131ce617bd356e3b1c7a
BLAKE2b-256 checksum
How to use checksums
be12a7f0c3d5ea3192b06e18d573b77ea40e945f3ff386971505f6f1ae518ba7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.2 Linux/6.5.0-42-generic

Release files / gemnine-0.1.13-py3-none-any.whl

Download URL gemnine-0.1.13-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b5a8aa317cef3824caecfe1d6b0007e3a64ae6e73b0396a8cbafc171ba15cce
BLAKE2b-256 checksum
How to use checksums
e9db5f659a3ed394b3487f46d7a774588906ddc19aaddc2b50d11e2a739724b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.2 Linux/6.5.0-42-generic

Security for gemnine 0.1.13

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.

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