googlebardapi


Namegooglebardapi JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/dsdanielpark/Bard-API
SummaryThe python package that returns Response of Google Bard through API.
upload_time2023-05-18 08:02:30
maintainer
docs_urlNone
authordaniel park
requires_python>=3.6
license
keywords python api bard google bard large language model chatbot api google api chatbot
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Development Status :: 5 - Production/Stable


# Google <a href="https://bard.google.com/"><img src="https://camo.githubusercontent.com/adb54264fe2ad5067d07d0752fc32600b4e6250073b01ce8c386575b431e3f06/68747470733a2f2f7777772e677374617469632e636f6d2f6c616d64612f696d616765732f66617669636f6e5f76315f31353031363063646466663766323934636533302e737667" height="20px"></a> Bard API 


<p align="left">
<a><img alt="PyPI package" src="https://img.shields.io/badge/pypi-BardAPI-black"></a>
<!-- <a href="https://pepy.tech/project/bardapi"><img alt="Downloads" src="https://pepy.tech/badge/bardapi"></a> -->
<!-- <a><img alt="commit update" src="https://img.shields.io/github/last-commit/dsdanielpark/Bard-API?color=black"></a> -->
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://github.com/dsdanielpark/Bard-API"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdsdanielpark%2FBARD_API&count_bg=%23000000&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=BardAPI&edge_flat=false"/></a>
<a href="https://pypi.org/project/bardapi/"><img alt="PyPI" src="https://img.shields.io/pypi/v/bardapi"></a>
</p>

> The python package that returns response of [Google Bard](https://bard.google.com/) through API.

![](./assets/bard_api.gif)


I referred to [this github repository(github.com/acheong08/Bard)](https://github.com/acheong08/Bard) where inference process of Bard was reverse engineered. Using `__Secure-1PSID`, you can ask questions and get answers from Google Bard. This package is designed for application to the Python package [ExceptNotifier](https://github.com/dsdanielpark/ExceptNotifier) and [Co-Coder](https://github.com/dsdanielpark/Co-Coder). 

<br>

Do not expose the `__Secure-1PSID`
> Note that while I referred to `__Secure-1PSID` value as an API KEY for convenience, it is not an officially provided API KEY. 

<br>

##  [Amazing Bard Prompts](https://github.com/dsdanielpark/amazing-bard-prompts) Is All You Need!
- Helpful prompts for Google Bard

<br>

## Install
The latest stable release (and required dependencies) can be installed from PyPI:
```
pip install bardapi
```
You may instead want to use the development version from Github:
```
pip install git+https://github.com/dsdanielpark/Bard-API.git
```

<br>

## Authentication
1. Visit https://bard.google.com/
2. F12 for console
3. Session: Application → Cookies → Copy the value of  `__Secure-1PSID` cookie.

<br>

## Usage 
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1YIMA8aBmEQSSk90bB0Q9tznaLLQcluGA?usp=share_link) 


Simple Usage

```python
from bardapi import Bard

token = 'xxxxxxxxxx'
bard = Bard(token=token)
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']
```
Or you can use this
```python
from bardapi import Bard
import os
os.environ['_BARD_API_KEY']="xxxxxxxx"

Bard().get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']
```

To get reponse dictionary
```python
import bardapi
import os

# set your __Secure-1PSID value to key
token = 'xxxxxxxxxx'

# set your input text
input_text = "나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘"

# Send an API request and get a response.
response = bardapi.core.Bard(token).get_answer(input_text)
```



Addressing errors caused by delayed responses in environments like Google Colab and containers. If an error occurs despite following the proper procedure, utilize the timeout argument.
```python
from bardapi import Bard
import os
os.environ['_BARD_API_KEY']="xxxxxxxx"

bard = Bard(timeout=30) # Set timeout in seconds
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']
```

<br>

## Futher
### Behind a proxy
If you are working behind a proxy, use the following.
```python
from bardapi import Bard
import os
os.environ['_BARD_API_KEY']="xxxxxxxx"

# Change 'http://127.0.0.1:1080' to your http proxy
# timeout in seconds
bard = Bard(proxies={'http':'http://127.0.0.1:1080', 'https':'http://127.0.0.1:1080'}, timeout=10)
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']
```

### Reusable session object
```python
from bardapi import Bard
import os
import requests
os.environ['_BARD_API_KEY'] = 'xxxxxxxxxxx'
# token='xxxxxxxxxxx'

session = requests.Session()
session.headers = {
            "Host": "bard.google.com",
            "X-Same-Domain": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
            "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
            "Origin": "https://bard.google.com",
            "Referer": "https://bard.google.com/",
        }
session.cookies.set("__Secure-1PSID", os.getenv("_BARD_API_KEY")) 
# session.cookies.set("__Secure-1PSID", token) 

bard = Bard(session=session, timeout=30)
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']
```

Simple Example
<br>

<a href="https://bard.google.com/"><img src="./assets/bardimg.png" height="600px">

<br>


## Scripts
In the scripts [folder](./scripts/), I have released a script to help you compare [OpenAI-ChatGPT](./scripts/openai_api.ipynb) and [Google-Bard](./scripts/google_api.ipynb). I hope they will help more developers.

## License
[MIT](https://opensource.org/license/mit/) <br>
I hold no legal responsibility; for more information, please refer to the bottom of the readme file. I just want you to give me and [them](https://github.com/acheong08/Bard) a star.


## Bugs and Issues
Sincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated.

## Contacts
- Core maintainer: [Daniel Park, South Korea](https://github.com/DSDanielPark) <br>
- E-mail: parkminwoo1991@gmail.com <br>

## Reference 
[1] https://github.com/acheong08/Bard
  
### Important Notice
  The user assumes all legal responsibilities associated with using the BardAPI package. This Python package merely facilitates easy access to Google Bard for developers. Users are solely responsible for managing data and using the package appropriately. For further information, please consult the Google Bard Official Document.
  

#### Could you kindly add this badge to your repository?
markdown
```
![BardAPI](https://img.shields.io/badge/pypi-BardAPI-black)
```
html
```
<a href="https://github.com/dsdanielpark/Bard-API"><img alt="PyPI package" src="https://img.shields.io/badge/pypi-BardAPI-black"></a>
```
Thank you for your interest.

  
*Copyright (c) 2023 MinWoo Park, South Korea*<br>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dsdanielpark/Bard-API",
    "name": "googlebardapi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "Python,API,Bard,Google Bard,Large Language Model,Chatbot API,Google API,Chatbot",
    "author": "daniel park",
    "author_email": "parkminwoo1991@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a4/e8/ad4c68e0096072e935d88df188749d18014c8c4dc3230df5cd06e32c956b/googlebardapi-0.1.1.tar.gz",
    "platform": null,
    "description": "Development Status :: 5 - Production/Stable\r\n\r\n\r\n# Google <a href=\"https://bard.google.com/\"><img src=\"https://camo.githubusercontent.com/adb54264fe2ad5067d07d0752fc32600b4e6250073b01ce8c386575b431e3f06/68747470733a2f2f7777772e677374617469632e636f6d2f6c616d64612f696d616765732f66617669636f6e5f76315f31353031363063646466663766323934636533302e737667\" height=\"20px\"></a> Bard API \r\n\r\n\r\n<p align=\"left\">\r\n<a><img alt=\"PyPI package\" src=\"https://img.shields.io/badge/pypi-BardAPI-black\"></a>\r\n<!-- <a href=\"https://pepy.tech/project/bardapi\"><img alt=\"Downloads\" src=\"https://pepy.tech/badge/bardapi\"></a> -->\r\n<!-- <a><img alt=\"commit update\" src=\"https://img.shields.io/github/last-commit/dsdanielpark/Bard-API?color=black\"></a> -->\r\n<a href=\"https://github.com/psf/black\"><img alt=\"Code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"></a>\r\n<a href=\"https://github.com/dsdanielpark/Bard-API\"><img src=\"https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdsdanielpark%2FBARD_API&count_bg=%23000000&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=BardAPI&edge_flat=false\"/></a>\r\n<a href=\"https://pypi.org/project/bardapi/\"><img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/bardapi\"></a>\r\n</p>\r\n\r\n> The python package that returns response of [Google Bard](https://bard.google.com/) through API.\r\n\r\n![](./assets/bard_api.gif)\r\n\r\n\r\nI referred to [this github repository(github.com/acheong08/Bard)](https://github.com/acheong08/Bard) where inference process of Bard was reverse engineered. Using `__Secure-1PSID`, you can ask questions and get answers from Google Bard. This package is designed for application to the Python package [ExceptNotifier](https://github.com/dsdanielpark/ExceptNotifier) and [Co-Coder](https://github.com/dsdanielpark/Co-Coder). \r\n\r\n<br>\r\n\r\nDo not expose the `__Secure-1PSID`\r\n> Note that while I referred to `__Secure-1PSID` value as an API KEY for convenience, it is not an officially provided API KEY. \r\n\r\n<br>\r\n\r\n##  [Amazing Bard Prompts](https://github.com/dsdanielpark/amazing-bard-prompts) Is All You Need!\r\n- Helpful prompts for Google Bard\r\n\r\n<br>\r\n\r\n## Install\r\nThe latest stable release (and required dependencies) can be installed from PyPI:\r\n```\r\npip install bardapi\r\n```\r\nYou may instead want to use the development version from Github:\r\n```\r\npip install git+https://github.com/dsdanielpark/Bard-API.git\r\n```\r\n\r\n<br>\r\n\r\n## Authentication\r\n1. Visit https://bard.google.com/\r\n2. F12 for console\r\n3. Session: Application \u2192 Cookies \u2192 Copy the value of  `__Secure-1PSID` cookie.\r\n\r\n<br>\r\n\r\n## Usage \r\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1YIMA8aBmEQSSk90bB0Q9tznaLLQcluGA?usp=share_link) \r\n\r\n\r\nSimple Usage\r\n\r\n```python\r\nfrom bardapi import Bard\r\n\r\ntoken = 'xxxxxxxxxx'\r\nbard = Bard(token=token)\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\nOr you can use this\r\n```python\r\nfrom bardapi import Bard\r\nimport os\r\nos.environ['_BARD_API_KEY']=\"xxxxxxxx\"\r\n\r\nBard().get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\n\r\nTo get reponse dictionary\r\n```python\r\nimport bardapi\r\nimport os\r\n\r\n# set your __Secure-1PSID value to key\r\ntoken = 'xxxxxxxxxx'\r\n\r\n# set your input text\r\ninput_text = \"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\"\r\n\r\n# Send an API request and get a response.\r\nresponse = bardapi.core.Bard(token).get_answer(input_text)\r\n```\r\n\r\n\r\n\r\nAddressing errors caused by delayed responses in environments like Google Colab and containers. If an error occurs despite following the proper procedure, utilize the timeout argument.\r\n```python\r\nfrom bardapi import Bard\r\nimport os\r\nos.environ['_BARD_API_KEY']=\"xxxxxxxx\"\r\n\r\nbard = Bard(timeout=30) # Set timeout in seconds\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\n\r\n<br>\r\n\r\n## Futher\r\n### Behind a proxy\r\nIf you are working behind a proxy, use the following.\r\n```python\r\nfrom bardapi import Bard\r\nimport os\r\nos.environ['_BARD_API_KEY']=\"xxxxxxxx\"\r\n\r\n# Change 'http://127.0.0.1:1080' to your http proxy\r\n# timeout in seconds\r\nbard = Bard(proxies={'http':'http://127.0.0.1:1080', 'https':'http://127.0.0.1:1080'}, timeout=10)\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\n\r\n### Reusable session object\r\n```python\r\nfrom bardapi import Bard\r\nimport os\r\nimport requests\r\nos.environ['_BARD_API_KEY'] = 'xxxxxxxxxxx'\r\n# token='xxxxxxxxxxx'\r\n\r\nsession = requests.Session()\r\nsession.headers = {\r\n            \"Host\": \"bard.google.com\",\r\n            \"X-Same-Domain\": \"1\",\r\n            \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36\",\r\n            \"Content-Type\": \"application/x-www-form-urlencoded;charset=UTF-8\",\r\n            \"Origin\": \"https://bard.google.com\",\r\n            \"Referer\": \"https://bard.google.com/\",\r\n        }\r\nsession.cookies.set(\"__Secure-1PSID\", os.getenv(\"_BARD_API_KEY\")) \r\n# session.cookies.set(\"__Secure-1PSID\", token) \r\n\r\nbard = Bard(session=session, timeout=30)\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\n\r\nSimple Example\r\n<br>\r\n\r\n<a href=\"https://bard.google.com/\"><img src=\"./assets/bardimg.png\" height=\"600px\">\r\n\r\n<br>\r\n\r\n\r\n## Scripts\r\nIn the scripts [folder](./scripts/), I have released a script to help you compare [OpenAI-ChatGPT](./scripts/openai_api.ipynb) and [Google-Bard](./scripts/google_api.ipynb). I hope they will help more developers.\r\n\r\n## License\r\n[MIT](https://opensource.org/license/mit/) <br>\r\nI hold no legal responsibility; for more information, please refer to the bottom of the readme file. I just want you to give me and [them](https://github.com/acheong08/Bard) a star.\r\n\r\n\r\n## Bugs and Issues\r\nSincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated.\r\n\r\n## Contacts\r\n- Core maintainer: [Daniel Park, South Korea](https://github.com/DSDanielPark) <br>\r\n- E-mail: parkminwoo1991@gmail.com <br>\r\n\r\n## Reference \r\n[1] https://github.com/acheong08/Bard\r\n  \r\n### Important Notice\r\n  The user assumes all legal responsibilities associated with using the BardAPI package. This Python package merely facilitates easy access to Google Bard for developers. Users are solely responsible for managing data and using the package appropriately. For further information, please consult the Google Bard Official Document.\r\n  \r\n\r\n#### Could you kindly add this badge to your repository?\r\nmarkdown\r\n```\r\n![BardAPI](https://img.shields.io/badge/pypi-BardAPI-black)\r\n```\r\nhtml\r\n```\r\n<a href=\"https://github.com/dsdanielpark/Bard-API\"><img alt=\"PyPI package\" src=\"https://img.shields.io/badge/pypi-BardAPI-black\"></a>\r\n```\r\nThank you for your interest.\r\n\r\n  \r\n*Copyright (c) 2023 MinWoo Park, South Korea*<br>\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "The python package that returns Response of Google Bard through API.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/dsdanielpark/Bard-API"
    },
    "split_keywords": [
        "python",
        "api",
        "bard",
        "google bard",
        "large language model",
        "chatbot api",
        "google api",
        "chatbot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2393fc77a2dabfd2a1ed92e3f6001445bafa2a3d80df31bc1dcf539f2be813ad",
                "md5": "4f3241eb474cf0c1ddc1bf050a94a113",
                "sha256": "e411b3019c964705f3395edc604bbe22036aa8b35684344530d451ea514250a2"
            },
            "downloads": -1,
            "filename": "googlebardapi-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f3241eb474cf0c1ddc1bf050a94a113",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6960,
            "upload_time": "2023-05-18T08:02:27",
            "upload_time_iso_8601": "2023-05-18T08:02:27.016236Z",
            "url": "https://files.pythonhosted.org/packages/23/93/fc77a2dabfd2a1ed92e3f6001445bafa2a3d80df31bc1dcf539f2be813ad/googlebardapi-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4e8ad4c68e0096072e935d88df188749d18014c8c4dc3230df5cd06e32c956b",
                "md5": "f45899a57fbd91cf7e195e523f0f2088",
                "sha256": "85ce7183299328b5741fdb06f10b4f6cc78cb5442d89dc347bd31617386a9fe2"
            },
            "downloads": -1,
            "filename": "googlebardapi-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f45899a57fbd91cf7e195e523f0f2088",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6936,
            "upload_time": "2023-05-18T08:02:30",
            "upload_time_iso_8601": "2023-05-18T08:02:30.291456Z",
            "url": "https://files.pythonhosted.org/packages/a4/e8/ad4c68e0096072e935d88df188749d18014c8c4dc3230df5cd06e32c956b/googlebardapi-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-18 08:02:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dsdanielpark",
    "github_project": "Bard-API",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "googlebardapi"
}
        
Elapsed time: 1.08749s