Skip to main content

A user-friendly wrapper for the Google Gemini 2.0 API

Project description

Gemini 2.0 API Wrapper

A powerful, user-friendly Python wrapper for the Google Gemini 2.0 API, featuring a modern interface with strong type hints, streaming support, and comprehensive documentation.

PyPI version Python Versions License: MIT Code style: black

Features

  • 🚀 Modern, intuitive API interface
  • 🔒 Type-safe with comprehensive type hints
  • 🌊 Streaming support for all operations
  • 💬 Advanced chat functionality with history management
  • 🎯 Model fine-tuning capabilities
  • 🖼️ Image analysis and vision model support
  • 📦 Pydantic models for robust data validation
  • ⚡ Async support for high-performance applications
  • 🔬 Mock-friendly design for testing
  • 📚 Detailed documentation with examples

Installation

Install using pip:

pip install gemini-2.0-api

Quick Start

from gemini_2_0_api import GeminiClient, TextGenerator

# Initialize client (using environment variable GEMINI_API_KEY)
client = GeminiClient.from_env()
generator = TextGenerator(client)

# Generate text
response = generator.generate("Tell me a story about a magical forest")
print(response.text)

# Use streaming
for chunk in generator.generate("Tell me a longer story", stream=True):
    print(chunk.text, end="")

# Chat functionality
from gemini_2_0_api import Chat

chat = Chat(client, system_prompt="You are a helpful assistant")
response = chat.send("What is machine learning?")
print(response.text)

follow_up = chat.send("Can you provide some examples?")
print(follow_up.text)

# Image analysis
from PIL import Image

image = Image.open("path/to/image.jpg")
response = generator.generate([
    "What can you see in this image?",
    image
])
print(response.text)

# Model tuning
from gemini_2_0_api import ModelTuner, TuningExample

tuner = ModelTuner(client)
examples = [
    TuningExample(
        input_text="What is 2+2?",
        output_text="4"
    ),
    TuningExample(
        input_text="What is 3+3?",
        output_text="6"
    )
]

model_id = tuner.tune(examples)
print(f"Tuned model ID: {model_id}")

Documentation

For detailed documentation and examples, see:

Advanced Usage

Configuration

from gemini_2_0_api import GeminiClient, GenerationConfig

# Direct initialization with API key
client = GeminiClient(api_key="your-api-key-here")

# Custom configuration
config = GenerationConfig(
    temperature=0.9,
    max_output_tokens=1000,
    top_p=0.8
)

response = generator.generate(
    "Write a creative story",
    config=config
)

Streaming with Progress

from gemini_2_0_api import TextGenerator
import sys

generator = TextGenerator(client)

print("Generating story...", end="")
sys.stdout.flush()

for chunk in generator.generate(
    "Tell me an epic story",
    stream=True
):
    print(chunk.text, end="")
    sys.stdout.flush()

Chat with History

from gemini_2_0_api import Chat

chat = Chat(
    client,
    system_prompt="You are a knowledgeable professor"
)

# Send messages and get responses
response1 = chat.send("What is quantum physics?")
response2 = chat.send("Can you explain that simpler?")

# Access chat history
for message in chat.get_history():
    print(f"{message.role}: {message.content}")

Image Analysis with Options

from gemini_2_0_api import TextGenerator
from PIL import Image

generator = TextGenerator(client)

image = Image.open("scene.jpg")
response = generator.generate([
    "Analyze this image in detail. Focus on:",
    "1. Main subjects",
    "2. Colors and lighting",
    "3. Mood and atmosphere",
    image
])

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

gemini_2_0_api-0.1.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

gemini_2_0_api-0.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file gemini_2_0_api-0.1.0.tar.gz.

File metadata

  • Download URL: gemini_2_0_api-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.0 CPython/3.13.2 Windows/11

File hashes

Hashes for gemini_2_0_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 206553b37994ee65c1e9f411e02fddddebd6f8f6735bbb65935a023837f75443
MD5 7b7aa61af3c69db7f224616015a597e1
BLAKE2b-256 428445292ad7ee267d90298d0bf481f99a183dbfa1727e4c29fc4fa426f4ef28

See more details on using hashes here.

File details

Details for the file gemini_2_0_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gemini_2_0_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.0 CPython/3.13.2 Windows/11

File hashes

Hashes for gemini_2_0_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c335dc4ffb79e3f2dd9b0adb281eaf7e88937b5853ddec7196093205f066493
MD5 b752936a143ea9575a3610bc2a736f8f
BLAKE2b-256 9fb788ba1793717b3902b404f42f63d5168dc9fb7d8d0c5071d45fc301c310c0

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