Skip to main content

Gemini Icon Gemini-API

Reverse-engineered asynchronous python wrapper for Google Gemini (formerly Bard) web client, providing a simple and elegant interface inspired by Google GenerativeAI's official API.

Installation

pip install gemini-webapi

Authentication

  • Go to https://gemini.google.com/ and login with your Google account
  • Press F12 for web inspector, go to Network tab and refresh the page
  • Click any request and copy cookie values of __Secure-1PSID and __Secure-1PSIDTS

Usage

Initialization

from gemini import GeminiClient

# Replace "COOKIE VALUE HERE" with your actual cookie values as strings
Secure_1PSID = "COOKIE VALUE HERE"
Secure_1PSIDTS = "COOKIE VALUE HERE"

client = GeminiClient(Secure_1PSID, Secure_1PSIDTS, proxy=None)
await client.init()

Generate contents from text inputs

response = await client.generate_content("Hello World!")
print(response.text)  # Note: simply use print(response) to get the same output if you just want to see the response text

Retrieve images in response

response = await client.generate_content("Send me some pictures of cats")
images = response.images
for image in images:
    print(f"{image.title}({image.url}) - {image.alt}", sep="\n")

Conversations across multiple turns

chat = client.start_chat()  # A chat stores the metadata to keep a conversation continuous. It will automatically get updated after each turn
response1 = await chat.send_message("Briefly introduce Europe")
response2 = await chat.send_message("What's the population there?")
print(response1.text, response2.text, sep="\n----------------------------------\n")

Check and switch to other answer candidates

chat = client.start_chat()
response = await chat.send_message("What's the best Japanese dish in your mind? Choose one only.")
for candidate in response.candidates:
    print(candidate, "\n----------------------------------\n")

# Control the ongoing conversation flow by choosing candidate manually
new_candidate = chat.choose_candidate(index=1) # Choose the second candidate here
followup_response = await chat.send_message("Tell me more about it.")  # Will generate contents based on the chosen candidate
print(new_candidate, followup_response, sep="\n----------------------------------\n")

Metadata

Release files for gemini-webapi 0.0.1

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

Source distribution (sdist)

Source distribution for gemini-webapi 0.0.1
File Size Uploaded Provenance Actions
gemini-webapi-0.0.1.tar.gz 11.2 kB Without provenance Details for gemini-webapi-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gemini-webapi 0.0.1
File Interpreter ABI Platform Actions
gemini_webapi-0.0.1-py3-none-any.whl Python 3 none any Details for gemini_webapi-0.0.1-py3-none-any.whl

Total release size: 19.3 kB

Release files / gemini-webapi-0.0.1.tar.gz

Download URL gemini-webapi-0.0.1.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6a4b54efbecd13ab8ca5bdb08530c9673ec856a58d12e0d373bbb58d46784b93
BLAKE2b-256 checksum
How to use checksums
a229b903136792561178c9e0d4c52a1995c7e53a6e9a65db1c499a6f71c939c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / gemini_webapi-0.0.1-py3-none-any.whl

Download URL gemini_webapi-0.0.1-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
064be5688d02679c6f61dd702048f5767075f1ebeb7937a7701ad78c7fd44ef3
BLAKE2b-256 checksum
How to use checksums
9392788f448e6badcf743753bf771169a9920ec7b1d2ff8bd5c6a18a97798b44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Security for gemini-webapi 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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