# Google AI Python SDK
[](https://badge.fury.io/py/google-generativeai)


The Google AI Python SDK enables developers to use Google's state-of-the-art generative AI
models (like Gemini and PaLM) to build AI-powered features and applications. This SDK
supports use cases like:
- Generate text from text-only input
- Generate text from text-and-images input (multimodal) (for Gemini only)
- Build multi-turn conversations (chat)
- Embedding
For example, with just a few lines of code, you can access Gemini's multimodal
capabilities to generate text from text-and-image input:
```python
model = genai.GenerativeModel('gemini-pro-vision')
cookie_picture = {
'mime_type': 'image/png',
'data': Path('cookie.png').read_bytes()
}
prompt = "Give me a recipe for this:"
response = model.generate_content(
content=[prompt, cookie_picture]
)
print(response.text)
```
## Try out the API
Install from PyPI.
`pip install google-generativeai`
[Obtain an API key from AI Studio](https://makersuite.google.com/app/apikey),
then configure it here.
Import the SDK and load a model.
```python
import google.generativeai as genai
genai.configure(api_key=os.environ["API_KEY"])
model = genai.GenerativeModel('gemini-pro')
```
Use `GenerativeModel.generate_content` to have the model complete some initial text.
```python
response = model.generate_content("The opposite of hot is")
print(response.text) # cold.
```
Use `GenerativeModel.start_chat` to have a discussion with a model.
```python
chat = model.start_chat()
response = chat.send_message('Hello, what should I have for dinner?')
print(response.text) # 'Here are some suggestions...'
response = chat.send_message("How do I cook the first one?")
```
## Installation and usage
Run [`pip install google-generativeai`](https://pypi.org/project/google-generativeai).
For detailed instructions, you can find a
[quickstart](https://ai.google.dev/tutorials/python_quickstart) for the Google AI
Python SDK in the Google documentation.
This quickstart describes how to add your API key and install the SDK in your app,
initialize the model, and then call the API to access the model. It also describes some
additional use cases and features, like streaming, embedding, counting tokens, and
controlling responses.
## Documentation
Find complete documentation for the Google AI SDKs and the Gemini model in the Google
documentation: https://ai.google.dev/docs
## Contributing
See [Contributing](https://github.com/google/generative-ai-python/blob/main/CONTRIBUTING.md) for more information on contributing to the Google AI Python SDK.
## Developers who use the PaLM API
### Migrate to use the Gemini API
Check our [migration guide](https://ai.google.dev/docs/migration_guide) in the Google
documentation.
### Installation and usage for the PaLM API
Install from PyPI.
`pip install google-generativeai`
[Obtain an API key from AI Studio](https://makersuite.google.com/app/apikey), then
configure it here.
```python
import google.generativeai as palm
palm.configure(api_key=os.environ["PALM_API_KEY"])
```
Use `palm.generate_text` to have the model complete some initial text.
```python
response = palm.generate_text(prompt="The opposite of hot is")
print(response.result) # cold.
```
Use `palm.chat` to have a discussion with a model.
```python
response = palm.chat(messages=["Hello."])
print(response.last) # 'Hello! What can I help you with?'
response.reply("Can you tell me a joke?")
```
### Documentation for the PaLM API
- [General PaLM documentation](https://ai.google.dev/docs/palm_api_overview)
- [Text quickstart](https://github.com/google/generative-ai-docs/blob/main/site/en/palm_docs/text_quickstart.ipynb)
- [Chat quickstart](https://github.com/google/generative-ai-docs/blob/main/site/en/palm_docs/chat_quickstart.ipynb)
- [Tuning quickstart](https://github.com/google/generative-ai-docs/blob/main/site/en/palm_docs/tuning_quickstart_python.ipynb)
### Colab magics
```
%pip install -q google-generativeai
%load_ext google.generativeai.notebook
```
Once installed, use the Python client via the `%%llm` Colab magic. Read the full guide [here](https://developers.generativeai.google/tools/notebook_magic).
```python
%%llm
The best thing since sliced bread is
```
## License
The contents of this repository are licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
Raw data
{
"_id": null,
"home_page": "https://github.com/google/generative-ai-python",
"name": "google-generativeai-gen",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/95/1f/34500cd97f606570f17e390790fa679c386d137c4e700ccd3e315404b543/google-generativeai_gen-1.0.9.tar.gz",
"platform": "Posix; MacOS X; Windows",
"description": "# Google AI Python SDK\n\n[](https://badge.fury.io/py/google-generativeai)\n\n\n\nThe Google AI Python SDK enables developers to use Google's state-of-the-art generative AI\nmodels (like Gemini and PaLM) to build AI-powered features and applications. This SDK\nsupports use cases like:\n\n- Generate text from text-only input\n- Generate text from text-and-images input (multimodal) (for Gemini only)\n- Build multi-turn conversations (chat)\n- Embedding\n\nFor example, with just a few lines of code, you can access Gemini's multimodal\ncapabilities to generate text from text-and-image input:\n\n```python\nmodel = genai.GenerativeModel('gemini-pro-vision')\n\ncookie_picture = {\n 'mime_type': 'image/png',\n 'data': Path('cookie.png').read_bytes()\n}\nprompt = \"Give me a recipe for this:\"\n\nresponse = model.generate_content(\n content=[prompt, cookie_picture]\n)\nprint(response.text)\n```\n\n\n## Try out the API\n\nInstall from PyPI.\n\n`pip install google-generativeai`\n\n[Obtain an API key from AI Studio](https://makersuite.google.com/app/apikey),\nthen configure it here.\n\nImport the SDK and load a model.\n\n```python\nimport google.generativeai as genai\n\ngenai.configure(api_key=os.environ[\"API_KEY\"])\n\nmodel = genai.GenerativeModel('gemini-pro')\n```\n\nUse `GenerativeModel.generate_content` to have the model complete some initial text.\n\n```python\nresponse = model.generate_content(\"The opposite of hot is\")\nprint(response.text) # cold.\n```\n\nUse `GenerativeModel.start_chat` to have a discussion with a model.\n\n```python\nchat = model.start_chat()\nresponse = chat.send_message('Hello, what should I have for dinner?')\nprint(response.text) # 'Here are some suggestions...'\nresponse = chat.send_message(\"How do I cook the first one?\")\n```\n\n\n\n## Installation and usage\n\nRun [`pip install google-generativeai`](https://pypi.org/project/google-generativeai).\n\nFor detailed instructions, you can find a\n[quickstart](https://ai.google.dev/tutorials/python_quickstart) for the Google AI\nPython SDK in the Google documentation.\n\nThis quickstart describes how to add your API key and install the SDK in your app,\ninitialize the model, and then call the API to access the model. It also describes some\nadditional use cases and features, like streaming, embedding, counting tokens, and\ncontrolling responses.\n\n\n## Documentation\n\nFind complete documentation for the Google AI SDKs and the Gemini model in the Google\ndocumentation: https://ai.google.dev/docs\n\n\n## Contributing\n\nSee [Contributing](https://github.com/google/generative-ai-python/blob/main/CONTRIBUTING.md) for more information on contributing to the Google AI Python SDK.\n\n## Developers who use the PaLM API\n\n### Migrate to use the Gemini API\n\nCheck our [migration guide](https://ai.google.dev/docs/migration_guide) in the Google\ndocumentation.\n\n### Installation and usage for the PaLM API\n\nInstall from PyPI.\n\n`pip install google-generativeai`\n\n[Obtain an API key from AI Studio](https://makersuite.google.com/app/apikey), then\nconfigure it here.\n\n```python\nimport google.generativeai as palm\n\npalm.configure(api_key=os.environ[\"PALM_API_KEY\"])\n```\n\nUse `palm.generate_text` to have the model complete some initial text.\n\n```python\nresponse = palm.generate_text(prompt=\"The opposite of hot is\")\nprint(response.result) # cold.\n```\n\nUse `palm.chat` to have a discussion with a model.\n\n```python\nresponse = palm.chat(messages=[\"Hello.\"])\nprint(response.last) # 'Hello! What can I help you with?'\nresponse.reply(\"Can you tell me a joke?\")\n```\n\n### Documentation for the PaLM API\n\n- [General PaLM documentation](https://ai.google.dev/docs/palm_api_overview)\n\n- [Text quickstart](https://github.com/google/generative-ai-docs/blob/main/site/en/palm_docs/text_quickstart.ipynb)\n\n- [Chat quickstart](https://github.com/google/generative-ai-docs/blob/main/site/en/palm_docs/chat_quickstart.ipynb)\n\n- [Tuning quickstart](https://github.com/google/generative-ai-docs/blob/main/site/en/palm_docs/tuning_quickstart_python.ipynb)\n\n### Colab magics\n\n```\n%pip install -q google-generativeai\n%load_ext google.generativeai.notebook\n```\n\nOnce installed, use the Python client via the `%%llm` Colab magic. Read the full guide [here](https://developers.generativeai.google/tools/notebook_magic).\n\n```python\n%%llm\nThe best thing since sliced bread is\n```\n\n## License\n\nThe contents of this repository are licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Google Generative AI High level API client library and tools.",
"version": "1.0.9",
"project_urls": {
"Homepage": "https://github.com/google/generative-ai-python"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0a3333ed897a9573c6742ac944988e4d88f0588c7c95203f5376e5019561606b",
"md5": "acef8c34ddca6431829ebea7155e3262",
"sha256": "72d392745f3339d8719c9faf85788b6a823159bcbaf18a0936efc040e9c7d9cc"
},
"downloads": -1,
"filename": "google_generativeai_gen-1.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "acef8c34ddca6431829ebea7155e3262",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 128426,
"upload_time": "2024-02-07T15:23:07",
"upload_time_iso_8601": "2024-02-07T15:23:07.790613Z",
"url": "https://files.pythonhosted.org/packages/0a/33/33ed897a9573c6742ac944988e4d88f0588c7c95203f5376e5019561606b/google_generativeai_gen-1.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "951f34500cd97f606570f17e390790fa679c386d137c4e700ccd3e315404b543",
"md5": "6a6464d4900e907fdea84002eb71b754",
"sha256": "1e604b887e0b30ecb7dfa185ed2df5334579fbf1afca95e6c8d3dfe890e5db8f"
},
"downloads": -1,
"filename": "google-generativeai_gen-1.0.9.tar.gz",
"has_sig": false,
"md5_digest": "6a6464d4900e907fdea84002eb71b754",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 108202,
"upload_time": "2024-02-07T15:23:09",
"upload_time_iso_8601": "2024-02-07T15:23:09.473764Z",
"url": "https://files.pythonhosted.org/packages/95/1f/34500cd97f606570f17e390790fa679c386d137c4e700ccd3e315404b543/google-generativeai_gen-1.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-07 15:23:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "google",
"github_project": "generative-ai-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "google-generativeai-gen"
}