Skip to main content

Official Python SDK for the onetask API

Project description

Python 3.8

onetask API for Python

Official Python SDK for onetask.


You can use pip to install the library:

$ pip install onetask

Alternatively, you can just clone the repository and run the script:

$ python install


Before making requests to the API, you need to create an instance of the onetask client. You will have to use your account API key:

from onetask import Client
# Instantiate the client Using your API key
api_token = '<YOUR API TOKEN HERE>'
project_id = '<YOUR PROJECT ID HERE>'
client = Client(api_token=api_token, project_id=project_id)

# if you print the client, you will receive some further instructions

There are several ways how you can start using our SDK. We'll show them in the following order:

  1. Fetching Sample Records
  2. Writing Labeling Functions
  3. Testing Labeling Functions Locally
  4. Registering Labeling Functions
  5. Fetching Labeling Functions

Fetching Sample Records

max_number_samples = 100 # default value
record_list = client.get_sample_records(max_number_samples=max_number_samples)

Writing Labeling Functions

Once you correctly instantiated your Client, you can start accessing record and labeling function endpoints. Please always ensure that your labeling functions:

  • return label names that also exist in your project definition
  • have exactly one parameter; we execute labeling functions on a record-basis
  • If you need an import statement in your labeling functions, please check if it is given in the whitelisted libraries. If you need a library that we have not yet whitelisted, feel free to reach out to us.

The most straightforward way to create and register a labeling function is as follows:

def my_first_lf(record):
    Checks whether a headline contains clickbait-like terms.

    clickbait_terms = [
        'should', 'reasons', 'you', #...
    headline = record['attributes']['headline'].lower()
    for clickbait_term in clickbait_terms:
        if clickbait_term in headline:
            return 'Clickbait'
    return 'Regular'

lf_first = onetask.build_lf(my_first_lf)

def my_second_lf(record):
    Checks whether a headline starts with two digits.

    import re # standard regular expressions library
    pattern = "^[1-9][0-9]" # two digits at start of string
    headline = record['attributes']['headline'].lower()
    if re.match(pattern, headline):
        return 'Clickbait'

lf_second = onetask.build_lf(my_second_lf)

Testing Labeling Functions Locally

Before you register your labeling functions, you can run them on your local machine, e.g. to ensure syntactic correctness.

record_hit_list_first = lf_first.execute(record_list) # this runs locally

record_hit_list_second = lf_second.execute(record_list) # this runs locally

Registering Labeling Functions

If you defined (and optionally tested) your labeling functions, you can register them to your project. Once registered, these labeling functions will receive an internal id, which can be used to fetch them back.



Fetching Labeling Functions

You can always fetch your registered labeling functions.

lf_list = client.get_all_lfs()

If you have any further questions which are not covered by this README, please do not hesitate to contact us directly

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for onetask, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size onetask-0.0.3-py3-none-any.whl (13.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size onetask-0.0.3.tar.gz (12.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page