Skip to main content

A simple Python library for Google Gemini with memory support.

Project description

Dracula 🧛

A simple, elegant Python library for Google Gemini with powerful features. Built for developers who want to integrate AI into their projects without dealing with complex API setup.

Installation

pip install dracula-ai

Quick Start

from dracula import Dracula
from dotenv import load_dotenv
import os

load_dotenv()

ai = Dracula(api_key=os.getenv("GEMINI_API_KEY"))
response = ai.chat("Hello, who are you?")
print(response)

Parameters

Parameter Type Default Description
api_key str required Your Google Gemini API key
model str gemini-2.0-flash Gemini model name
max_messages int 10 Maximum number of messages to remember
prompt str "You are a helpful assistant." System prompt
temperature float 1.0 Response creativity (0.0 - 2.0)
max_output_tokens int 8192 Maximum response length
stats_filepath str "dracula_stats.json" Path to save usage stats
language str "English" Language for responses

Features

💬 Text Chat

The most basic feature of Dracula. Send a message to Gemini and get a response back. Every message you send and every response you receive is automatically stored in memory, so Gemini always knows the context of your conversation.

ai = Dracula(api_key="your-api-key")
response = ai.chat("What is Python?")
print(response)

🌊 Streaming

Normally, Dracula waits for Gemini to finish generating the full response before returning it. Streaming changes this behavior — instead of waiting, you receive the response word by word as it is being generated, just like ChatGPT does. This is especially useful for long responses or when you want a more interactive feel in your app.

for chunk in ai.stream("Tell me a long story."):
    print(chunk, end="", flush=True)

🧠 Conversation Memory

Dracula automatically remembers the conversation history so Gemini can refer back to previous messages. For example, if you tell it your name in one message, it will remember it in the next. You can control how many messages are remembered with the max_messages parameter. When you want to start a completely fresh conversation, use clear_memory().

ai.chat("My name is Ahmet.")
response = ai.chat("What is my name?")
print(response)  # It remembers! ✅

ai.clear_memory()  # Wipe memory

💾 Save & Load History

By default, conversation history only exists while your program is running. Once you stop the program, the history is lost. Save & Load History solves this by letting you save the conversation to a JSON file and reload it later, so your AI can continue right where it left off — even in a completely new run of your program.

ai.save_history("conversation.json")

# Later, in a new run of your program:
ai.load_history("conversation.json")

📜 Pretty Print History

get_history() returns the raw conversation history as a list of dictionaries, which can be hard to read. print_history() formats the same data into a clean, human-readable layout with clear labels for each message, making it much easier to follow the conversation at a glance.

ai.print_history()

🎭 System Prompt

The system prompt is a set of instructions you give to Gemini before the conversation starts. It defines the AI's personality, role, and behavior for the entire conversation. For example, you can tell it to act as a pirate, a chef, a formal assistant, or anything else you can imagine. The user will never see this prompt — it works silently in the background.

ai = Dracula(
    api_key="your-api-key",
    prompt="You are a pirate who answers everything dramatically."
)

# You can also change it anytime during the conversation:
ai.set_prompt("You are now a formal assistant.")

🌡️ Temperature Control

Temperature controls how creative and random Gemini's responses are. A low temperature (close to 0.0) makes responses more focused, predictable, and factual — great for technical questions. A high temperature (close to 2.0) makes responses more creative, surprising, and varied — great for storytelling or brainstorming. The default value of 1.0 is a balanced middle ground.

ai = Dracula(api_key="your-api-key", temperature=0.2)  # Focused
ai = Dracula(api_key="your-api-key", temperature=1.8)  # Creative

# You can also change it anytime:
ai.set_temperature(0.5)

📏 Max Output Tokens

Tokens are small chunks of text — roughly one token per word. max_output_tokens controls the maximum length of Gemini's responses. If you want short, concise answers set it low. If you want long, detailed responses set it high. The default is 8192 which is large enough for most use cases.

ai = Dracula(api_key="your-api-key", max_output_tokens=256)  # Short responses
ai = Dracula(api_key="your-api-key", max_output_tokens=8192) # Long responses

# You can also change it anytime:
ai.set_max_output_tokens(512)

🌍 Response Language

By default Gemini responds in whatever language the user writes in. The language feature overrides this behavior and forces Gemini to always respond in a specific language, regardless of what language the user writes in. This is useful for apps targeting a specific audience or for language learning tools.

ai = Dracula(api_key="your-api-key", language="Turkish")
response = ai.chat("Hello!")
print(response)  # Merhaba! ✅

# You can also change it anytime:
ai.set_language("Spanish")

📊 Usage Stats

Dracula automatically tracks how many messages you've sent and received, and how many characters were exchanged in total. These stats are saved to a JSON file and persist across sessions, so they accumulate over time. This is useful for monitoring your API usage or just satisfying your curiosity about how much you've chatted with your AI.

print(ai.get_stats())
# {
#   "total_messages": 5,
#   "total_responses": 5,
#   "total_characters_sent": 120,
#   "total_characters_received": 3400
# }

ai.reset_stats()  # Reset back to zero

🔗 Chainable Methods

Instead of calling each setter method on a separate line, chainable methods let you combine multiple settings into a single, clean line of code. This works because each setter method returns the Dracula object itself after making the change, allowing you to immediately call another method on it.

# Without chaining:
ai.set_prompt("You are a chef.")
ai.set_temperature(0.9)
ai.set_language("Turkish")

# With chaining — same result, much cleaner:
ai.set_prompt("You are a chef.").set_temperature(0.9).set_language("Turkish")

🧹 Context Manager

A context manager lets you use Dracula with Python's with statement. The benefit is automatic cleanup — when the with block ends, Dracula automatically clears the memory and resets the stats, even if an error occurred inside the block. This is the cleanest and safest way to use Dracula, especially in larger applications.

with Dracula(api_key="your-api-key") as ai:
    ai.chat("Hello!")
    ai.print_history()
# Memory and stats automatically reset here ✅

Error Handling

Dracula provides custom exceptions so you can handle different types of errors separately and give your users clear, meaningful error messages instead of confusing Python crashes.

from dracula import ValidationException, ChatException, InvalidAPIKeyException

try:
    ai = Dracula(api_key="", temperature=5.0)
except ValidationException as e:
    print(f"Validation error: {e}")
except InvalidAPIKeyException as e:
    print(f"API key error: {e}")
except ChatException as e:
    print(f"Chat error: {e}")

Getting Your API Key

  1. Go to https://aistudio.google.com
  2. Sign in with your Google account
  3. Click "Get API Key"
  4. Copy your key and store it safely in a .env file

License

MIT License — feel free to use this in your own projects!

Author

Suleyman Ibis

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

dracula_ai-0.3.7.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

dracula_ai-0.3.7-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file dracula_ai-0.3.7.tar.gz.

File metadata

  • Download URL: dracula_ai-0.3.7.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for dracula_ai-0.3.7.tar.gz
Algorithm Hash digest
SHA256 bd620b76c1edc65e39b6e7380df2b8f64e0949104ec03265f19ddb310b4c559a
MD5 e03914dd57aec8c93732bc79a698feb4
BLAKE2b-256 2b6717bbf0ea77d9afcd6f383961aad973dcf6a6a630b37638c056e356932cbd

See more details on using hashes here.

File details

Details for the file dracula_ai-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: dracula_ai-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for dracula_ai-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fccf27e4a1af2ea20b41ac93217e8560618cddf7be381ed2ab5377496cdfa253
MD5 e91896752b763a4bef026ca6bea6344d
BLAKE2b-256 d924785b607b8c925a9edf87d61ed9bfaef101ee8d129185ddca0ea21c3c3837

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