> For the complete documentation index, see [llms.txt](https://docs.backtick.se/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.backtick.se/python/s3/get-objects.md).

# Get objects

Load Python objects from an S3 bucket to Python

The following function can be used to get a Python object in an S3 bucket to Python. This works for any kind of Python object stored in S3, like `sklearn` models, arrays, `pandas` dataframes etc.

```python
from io import BytesIO
import joblib
import boto3

def get_obj(key, bucket):
    try:
        # memory buffer
        buffer = BytesIO()
        # download object from S3-bucket
        client = boto3.client('s3')
        client.download_fileobj(
            Fileobj=buffer,
            Bucket=bucket,
            Key=key,
        )
        # reset buffer position
        buffer.seek(0)
        # return object
        if buffer is None:
            return None
        return joblib.load(buffer)
    except:
        pass
```

When calling the function you need to pass

* `key` - the key ("filepath") of the object you want to get from the S3 bucket
* `bucket` - the name of the bucket

```python
key = 'key_name'
bucket = 'bucket_name'

# get python object from S3-bucket
obj = get_obj(key=key, bucket=bucket) 
```
