# <img src="https://www.gstatic.com/lamda/images/favicon_v1_150160cddff7f294ce30.svg" width="35px" alt="Bard Icon" /> Bard-API
Reverse-engineered asynchronous API for Google Bard providing a simple but elegant interface inspired by official Gemini API.
## Installation
```bash
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
```python
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
```python
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
```python
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
```python
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
```python
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")
```
Raw data
{
"_id": null,
"home_page": "",
"name": "bard-webapi",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "API,async,Bard,Google Bard,Google,Gemini,LLM",
"author": "UZQueen",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/72/09/b6c355e09d18b122b8dc2220e82cde80621e77a64ba23063acf1bf4369bb/bard-webapi-0.2.4.tar.gz",
"platform": null,
"description": "# <img src=\"https://www.gstatic.com/lamda/images/favicon_v1_150160cddff7f294ce30.svg\" width=\"35px\" alt=\"Bard Icon\" /> Bard-API\n\nReverse-engineered asynchronous API for Google Bard providing a simple but elegant interface inspired by official Gemini API.\n\n## Installation\n\n```bash\npip install bard-webapi\n```\n\n## Authentication\n\n- Go to <https://bard.google.com/> and login with your Google account\n- Press F12 for web inspector, go to `Network` tab and refresh the page\n- Click any request and copy cookie values of `__Secure-1PSID` and `__Secure-1PSIDTS`\n\n## Usage\n\n### Initialization\n\n```python\nfrom bard_webapi import BardClient\n\n# Replace \"COOKIE VALUE HERE\" with your actual cookie values as strings\nSecure_1PSID = \"COOKIE VALUE HERE\"\nSecure_1PSIDTS = \"COOKIE VALUE HERE\"\n\nclient = BardClient(Secure_1PSID, Secure_1PSIDTS, proxy=None)\nawait client.init()\n```\n\n### Generate contents from text inputs\n\n```python\nresponse = await client.generate_content(\"Hello World!\")\nprint(response.text) # Note: simply use print(response) to get the same output if you just want to see the response text\n```\n\n### Retrieve images in response\n\n```python\nresponse = await client.generate_content(\"Send me some pictures of cats\")\nimages = response.images\nfor image in images:\n print(f\"{image.title}({image.url}) - {image.alt}\", sep=\"\\n\")\n```\n\n### Conversations across multiple turns\n\n```python\nchat = client.start_chat() # A chat stores the metadata to keep a conversation continuous. It will automatically get updated after each turn\nresponse1 = await chat.send_message(\"Briefly introduce Europe\")\nresponse2 = await chat.send_message(\"What's the population there?\")\nprint(response1.text, response2.text, sep=\"\\n----------------------------------\\n\")\n```\n\n### Check and switch to other answer candidates\n\n```python\nchat = client.start_chat()\nresponse = await chat.send_message(\"What's the best Japanese dish in your mind? Choose one only.\")\nfor candidate in response.candidates:\n print(candidate, \"\\n----------------------------------\\n\")\n\n# Control the ongoing conversation flow by choosing candidate manually\nnew_candidate = chat.choose_candidate(index=1) # Choose the second candidate here\nfollowup_response = await chat.send_message(\"Tell me more about it.\") # Will generate contents based on the chosen candidate\nprint(new_candidate, followup_response, sep=\"\\n----------------------------------\\n\")\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Reverse-engineered async API for Google Bard inspired by Gemini",
"version": "0.2.4",
"project_urls": {
"Issues": "https://github.com/HanaokaYuzu/Bard-API/issues",
"Repository": "https://github.com/HanaokaYuzu/Bard-API"
},
"split_keywords": [
"api",
"async",
"bard",
"google bard",
"google",
"gemini",
"llm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ce8b4f59dfbed113925d3bfa61cee53b99de1c6784873d7022335331146becc0",
"md5": "94b7bc5867ece80b26f85ab04e935687",
"sha256": "21627ddf62f90ba1c36ccf60944fb8e5a7415b88b900a1bbfe3e33bd18bd1eaf"
},
"downloads": -1,
"filename": "bard_webapi-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "94b7bc5867ece80b26f85ab04e935687",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7836,
"upload_time": "2024-01-21T11:24:00",
"upload_time_iso_8601": "2024-01-21T11:24:00.627445Z",
"url": "https://files.pythonhosted.org/packages/ce/8b/4f59dfbed113925d3bfa61cee53b99de1c6784873d7022335331146becc0/bard_webapi-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7209b6c355e09d18b122b8dc2220e82cde80621e77a64ba23063acf1bf4369bb",
"md5": "ca5c58874243615aef5b41dfbad0ae6f",
"sha256": "9996122092c5487521d1e06535c66580691d4d8af3bea3d71ddd5cb26a647c32"
},
"downloads": -1,
"filename": "bard-webapi-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "ca5c58874243615aef5b41dfbad0ae6f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 10352,
"upload_time": "2024-01-21T11:24:02",
"upload_time_iso_8601": "2024-01-21T11:24:02.207133Z",
"url": "https://files.pythonhosted.org/packages/72/09/b6c355e09d18b122b8dc2220e82cde80621e77a64ba23063acf1bf4369bb/bard-webapi-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-21 11:24:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "HanaokaYuzu",
"github_project": "Bard-API",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "bard-webapi"
}