Skip to main content

LarryData

LarryData is a library of utilities for common data tasks using AWS for data science and data engineering projects. While boto3 is a great interface for interacting with AWS services, it can be overly complex for data scientists and others who want to perform straightforward operations on data. Boto3 is powerful but often requires you spend time worrying about API-specific interactions and parameters. LarryData makes it easy to use services like S3, MTurk, and other data-oriented AWS services in a far more functional manner to let you focus on the data rather than syntax. This library is designed to make getting tasks completed in Jupyter Notebooks or AWS Lambda functions as easy as possible by providing simplified interfaces while still giving you access to the underlying boto3 libraries when you need them.

Installation

pip install larrydata

In addition, you can easily add LarryData to your AWS Lambda functions by adding one of the following public Layers:

  • LarryData: arn:aws:lambda:us-west-2:981332165467:layer:LarryData:2
  • LarryData with Jinja2: arn:aws:lambda:us-west-2:981332165467:layer:LarryDataWithJinja:2
  • LarryData with Jinja2 and Pillow: arn:aws:lambda:us-west-2:981332165467:layer:LarryDataWithJinjaPillow:2

Configuring your AWS session

By default LarryData creates a boto3 session using your default AWS credentials that can be configured using the AWS CLI. To use a different profile, you can change using the following:

import larrydata as ld
ld.set_session(profile_name='my_profile')

Alternatively, you can pass AWS credentials directly

import larrydata as ld
ld.set_session(aws_access_key_id='XXXXXXXXXX', aws_secret_access_key='XXXXXXXXXXXXX')

Functional S3 interactions

When using boto3 alone, the following is how you would read in a JSON formatted object from S3 into a dict:

import boto3
import json

resource = boto3.resource('s3')
obj = resource.Bucket('mybucket').Object(key='myfile.json').get()
contents = obj['Body'].read()
my_dict = json.loads(contents.decode('utf-8'))

In contrast, LarryData takes care of all those steps for you and let's you simply call one function to get your data.

import larrydata as ld

my_dict = ld.s3.read_dict(bucket='mybucket', key='myfile.json')

In addition to accessing data using bucket/key pairs, you can S3 URIs like those commonly used in SageMaker.

my_dict2 = ld.s3.read_dict(uri='s3://mybucket/myfile.json')

To write files to S3, simply call write_object to write your object out in the appropriate format:

# Write json to S3
my_dict = {'key': 'val'}
ld.s3.write_object(my_dict, bucket='mybucket', key='myfile.json')

# Write a list of strings to S3 as rows
my_list = ['a','b','c','d']
ld.s3.write_object(my_list, bucket='mybucket', key='myfile.txt')

# Write a JSON lines file to S3 (commonly used for SageMaker manifest files)
my_dictlist = [{'a': 1}, {'b': 2}, {'c': 3}]
ld.s3.write_object(my_dictlist, bucket='mybucket', key='myfile.jsonl')

Powerful MTurk extensions

LarryData is especially useful for services like MTurk which have more complex interaction patterns and legacy aspects of their APIs. The MTurk module includes a number of features to make using MTurk much easier:

  • Easy toggling between sandbox and production clients (no more copy/pasting in endpoint urls)
  • Worker answers are converted into easy to access dict objects (no more QuestionFormAnswer XML!)
  • Potentially expensive operations such as list_hits and list_assignments_for_hit return generators
  • Utilities are included to easily generate HTMLQuestion and ExternalQuestion XML objects with integrated Jinja2 templating
  • Helpers to enable state data in the RequesterAnnotation field

The combination of these features means that creating a HIT in MTurk is as easy as the following:

import larrydata as ld

# Indicate we want to use the production environment
ld.mturk.use_production()

# Load a template from S3 and populate it with values
task_data = {'image_url': 'https://mywebsite.com/images/233.jpg'}
question_xml = ld.mturk.render_jinja_template_question(task_data, template_uri='s3://mybucket/templates/imageCat.html')

# Format the source data so it can be stored in the RequesterAnnotation field for use in tracking
task_data['request_id'] = 'MY_TRACKING_ID'
annotation_payload = ld.mturk.prepare_requester_annotation(task_data)

# Create a HIT
hit = ld.mturk.create_hit(title='Test task', description='Categorize images', reward='0.05', max_assignments=5,
                       lifetime=86400, assignment_duration=600, question=question_xml, annotation=annotation_payload)

# Display where the HIT can be viewed on the Worker website
hit_id = hit['HITId']
hit_type_id = hit['HITTypeId']
print('HIT {} created, preview at {}'.format(hit_id, ld.mturk.preview_url(hit_type_id)))

Getting the results from that task is as simple as the following:

import larrydata as ld

hit_id = 'HIT_ID_FROM_EARLIER'

# Indicate we want to use the production environment
ld.mturk.use_production()

# retrieve the HIT
hit = ld.mturk.get_hit(hit_id)

# retrieve the requester annotation data
task_data = ld.mturk.retrieve_requester_annotation(hit=hit)

# get the results
for assignment in ld.mturk.list_assignments_for_hit(hit_id):
    print('Worker {} responded with {}'.format(assignment['WorkerId'], assignment['Answer']['category']))

More features will be added over time, feel free to submit your feature suggestions.

Metadata

Release files for larrydata 0.2.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for larrydata 0.2.20
File Size Uploaded
larrydata-0.2.20.tar.gz 24.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for larrydata 0.2.20
File Interpreter ABI Platform
larrydata-0.2.20-py3-none-any.whl Python 3 none any Details

Total release size: 62.6 kB

Release files / larrydata-0.2.20.tar.gz

Download URL larrydata-0.2.20.tar.gz
Size 24.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4deb57f9c3c1e2c523402161832807088682a1b289048d220eb339722bda3700
BLAKE2b-256 checksum
How to use checksums
a261f3e651d11c808acdebaab9200b810a58eb74cae9a506dc62c4c001bce2e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.0

Release files / larrydata-0.2.20-py3-none-any.whl

Download URL larrydata-0.2.20-py3-none-any.whl
Size 37.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
887ff071b1b790dc80f7d87295edc4006f8bad83baad008ec906927d08c38dbd
BLAKE2b-256 checksum
How to use checksums
fee01e45af673fe1cab503ed3596a807c6f6012776dc24d516261f11ac7b9e5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.2.20 This release

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

3 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page