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.
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.gitcd roboflow-pythonpython3 -m venvsource venv/bin/activatepip3 install -r requirements.txt
The Python Package allows you to:
List information about workspaces, projects, and versions.
Upload images to your projects.
Perform inference with specific model versions.
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 Roboflowrf = 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() # orproject = rf.project("project-id")
You can upload a local image to this project by doing:
Next, if you want to access the versions of a specific project:
all_versions = project.versions() # orversion = 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.modelprediction = model.predict("YOUR_IMAGE.jpg") # orprediction_hosted = model.predict("https://www.yourimageurl.com", hosted=True)
You can plot and save a visualization of the prediction.
Or access your model's prediction as JSON.
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.