Skip to main content

Reverse-engineered async API for Google Bard inspired by Gemini

Project description

Bard Icon Bard-API

Reverse-engineered asynchronous API for Google Bard providing a simple but elegant interface inspired by official Gemini API.

Installation

pip install bard-webapi

Authentication

  • Go to https://bard.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 bard_webapi import BardClient

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

client = BardClient(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")

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

bard-webapi-0.2.4.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

bard_webapi-0.2.4-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file bard-webapi-0.2.4.tar.gz.

File metadata

  • Download URL: bard-webapi-0.2.4.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for bard-webapi-0.2.4.tar.gz
Algorithm Hash digest
SHA256 9996122092c5487521d1e06535c66580691d4d8af3bea3d71ddd5cb26a647c32
MD5 ca5c58874243615aef5b41dfbad0ae6f
BLAKE2b-256 7209b6c355e09d18b122b8dc2220e82cde80621e77a64ba23063acf1bf4369bb

See more details on using hashes here.

File details

Details for the file bard_webapi-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: bard_webapi-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for bard_webapi-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 21627ddf62f90ba1c36ccf60944fb8e5a7415b88b900a1bbfe3e33bd18bd1eaf
MD5 94b7bc5867ece80b26f85ab04e935687
BLAKE2b-256 ce8b4f59dfbed113925d3bfa61cee53b99de1c6784873d7022335331146becc0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page