Use Google Gemini from Python — Brand New SDK (Code example included!)

Abish Pius
3 min readDec 15, 2023

Google’s Gemini API introduces a powerful and versatile tool for data scientists and developers to tap into the capabilities of large language models. In this blog post, we’ll explore the Python SDK for the Gemini API and demonstrate its usage through various scenarios, ranging from text-only prompts to multi-turn conversations and multimodal inputs.

Colab Notebook Here: Google Gemini Starter


Before diving into the exciting world of Gemini, ensure your development environment meets the following requirements:

  • Python 3.9+
  • Jupyter installed for running notebooks


Install the Python SDK

Begin by installing the Python SDK for the Gemini API using pip:

pip install -q -U google-generativeai

Import Packages

Import the necessary packages for working with the Gemini API:

import pathlib
import textwrap
import google.generativeai as genai
# Used to securely store your API key
from google.colab import userdata
from IPython.display import display
from IPython.display import Markdown



Abish Pius

Data Science Professional, Python Enthusiast, turned LLM Engineer