If you need programmatic access to the Surge platform, look no further! You can use the Surge API to manage all aspects of your labeling project. Our open-source Python SDK provides convenient access to our API, with functions for creating new projects, running tasks, and much more.

In this blog post, we'll walk through the setup of a sample project from start to finish using our Python SDK.

1. Installation

If you haven't already, sign up for an account on Surge. Once you are logged in, go to your Profile page and copy your API key. This will be used to authenticate your API requests.

Next, use pip to install our Python package:

pip install --upgrade surge-api

2. Authentication

Your API key carries many privileges, so be sure to keep it secure! Do not share it in publicly accessible areas such as GitHub, client-side code, and so forth.

To use your API key, assign it to surge.api_key. The Python SDK will then automatically send this key to authenticate each request.

https://assets.website-files.com/610770ea9c21ff57ccb6a6a9/61077b70b71e4819485dbb5e_htxJHLLTFGGjKmGN.png

Alternatively, you can set your API key as an environment variable.

export SURGE_API_KEY=YOUR-API-KEY

3. Creating a project

Now, it's time to create a new labeling project. Let's make one to gather information about movie reviews.

Each project should have a list of questions to be completed by the labeling workforce. Surge supports a wide range of questions including multiple choice, free response, text tagging, bounding boxes, etc.

To create new questions, instantiate the desired Question objects. In this project, we will ask labelers to tag named entities in the movie review (text tagging), determine its sentiment (multiple choice), and write their very own review (free response).

https://assets.website-files.com/610770ea9c21ff57ccb6a6a9/61077b70561181569c23db69_LJLMubmJVOSPDtcr.png

Notice that the text associated with the text tagging question is {{review}}, which is a handlebars expression. The actual movie review will automatically replace this placeholder once we import data, which we'll do in the upcoming task creation step.

Once the questions have been created, simply pass them into the method surge.Project.create():

https://assets.website-files.com/610770ea9c21ff57ccb6a6a9/61077b71a4a2bc018cba2a29_oDHLNRmMdPhtQjjC.png