Select API Quickstart Guide Slack

Traditional retrieval of objects is always as whole entities, i.e GetObject for a 5 GiB object, will always return 5 GiB of data. S3 Select API allows us to retrieve a subset of data by using simple SQL expressions. By using Select API to retrieve only the data needed by the application, drastic performance improvements can be achieved.

You can use the Select API to query objects with following features:

Type inference and automatic conversion of values is performed based on the context when the value is un-typed (such as when reading CSV data). If present, the CAST function overrides automatic conversion.

1. Prerequisites

2. Install boto3

Install aws-sdk-python from AWS SDK for Python official docs here

3. Example

As an example, let us take a gzip compressed CSV file. Without S3 Select, we would need to download, decompress and process the entire CSV to get the data you needed. With Select API, can use a simple SQL expression to return only the data from the CSV you’re interested in, instead of retrieving the entire object. Following Python example shows how to retrieve the first column Location from an object containing data in CSV format.

Please replace endpoint_url,aws_access_key_id, aws_secret_access_key, Bucket and Key with your local setup in this file.

#!/usr/bin/env/env python3
import boto3

s3 = boto3.client('s3',

r = s3.select_object_content(
    Expression="select * from s3object s where s.Location like '%United States%'",
        'CSV': {
            "FileHeaderInfo": "USE",
        'CompressionType': 'GZIP',
    OutputSerialization={'CSV': {}},

for event in r['Payload']:
    if 'Records' in event:
        records = event['Records']['Payload'].decode('utf-8')
    elif 'Stats' in event:
        statsDetails = event['Stats']['Details']
        print("Stats details bytesScanned: ")
        print("Stats details bytesProcessed: ")

4. Run the Program

Upload a sample dataset to Minio using the following commands.

$ curl "" > TotalPopulation.csv
$ mc mb myminio/mycsvbucket
$ gzip TotalPopulation.csv
$ mc cp TotalPopulation.csv.gz myminio/mycsvbucket/sampledata/

Now let us proceed to run our select example to query for Location which matches United States.

$ python3
840,United States of America,2,Medium,1950,1950.5,79233.218,79571.179,158804.395

840,United States of America,2,Medium,1951,1951.5,80178.933,80726.116,160905.035

840,United States of America,2,Medium,1952,1952.5,81305.206,82019.632,163324.851

840,United States of America,2,Medium,1953,1953.5,82565.875,83422.307,165988.190

Stats details bytesScanned:
Stats details bytesProcessed:

For a more detailed SELECT SQL reference, please see here

5. Explore Further

6. Implementation Status