Python Package

Navigating the pip package

Most Roboflow users will interact with the platform through their web UI, but often times, workflows require Python integrations. The gold-standard for python packages is pip provided by PyPi.

The python package, over time, will be able to handle all actions you can perform on the web UI programmatically; although, for now a select number of operations are able to be performed. Please request any functionality you might need on the roboflow-python repository.

Installation

You can either install Roboflow through the PyPi package:

pip install roboflow

or manually through the GitHub:

git clone https://github.com/roboflow-ai/roboflow-python.git
cd roboflow-python
python3 -m venv
source venv/bin/activate
pip3 install -r requirements.txt

Overview

The Python Package allows you to:

  1. List information about workspaces, projects, and versions.

  2. Upload images to your projects.

  3. Perform inference with specific model versions.

  4. Visualize, and save predictions that you've made on the model.

Everything in the package works through the Roboflow() object. You must pass your private API key to the object, which can be found under the settings of your workspace. Full instructions for obtaining your API Key can be found here.

from roboflow import Roboflow
‚Äč
rf = Roboflow(api_key="YOUR_API_KEY")

You can then list all projects for your workspace or access the information for a specific project:

my_projects = rf.projects() # or
project = rf.project("project-id")

You can upload a local image to this project by doing:

project.upload("UPLOAD_IMAGE.jpg")

Next, if you want to access the versions of a specific project:

all_versions = project.versions() # or
version = project.version(1)

If you've trained a model on this version, you can perform inference on the model with either a local or hosted image:

model = version.model
prediction = model.predict("YOUR_IMAGE.jpg") # or
prediction_hosted = model.predict("https://www.yourimageurl.com", hosted=True)

You can plot and save a visualization of the prediction.

prediction.plot()
prediction.save(output_path="predictions.jpg")

Or access your model's prediction as JSON.

prediction.json()

To Be Continued

Just like the Roboflow REST API, our vision for the Roboflow Python pip package is to eventually reach feature parity with our web UI so you can automate and integrate any part of your Roboflow workflow into your own codebase.