Skip to main content

A polite interface for sending python objects to and from Amazon S3.

Project description

# s3pyo

A polite interface for sending python objects to and from Amazon S3.

## Installation

```
pip install s3pyo
```

## Tests

**NOTE** very basic for now. They also assume you have set `AWS_ACCESS_KEY_ID` and
`AWS_ACCESS_KEY_SECRET` as environmental variables and

```
nosetests
```

## Bacic Usage

```python

import s3pyo

# return an `s3pyo.S3` object with
# methods for sending objects
# to and from Amazon S3.

plz = s3pyo.please('s3://asteroid',
key='navigate',
secret='shield',
serializer="json.gz",
public = False
)

# You can also set `AWS_ACCESS_KEY_ID` and
# `AWS_ACCESS_KEY_SECRET` as environmental variables


# Serialize an object, format its
# filepath, put it on s3, and return
# the formatted filepath (with an absolute s3path)
# for your records

obj = {"key": "value"}
filepath = 'test/{key}.json.gz'

fp = plz.put(obj, filepath, **obj)
print fp

# >>> 's3://my-bucket/test/value.json.gz'
# you can now fetch this object with its filepath

obj = plz.get(fp)
assert(obj == obj)

```

## Customization.

## Filepaths

`s3pyo` will attempt to format your filepath
for you given arbitary `**kwargs` passed to
any method. You also have access to utility values
accessed by the "@" operator these include:

- '@second': "56"
- '@minute': "54"
- '@hour': : "23"
- '@day': "29"
- '@month': "01"
- '@year': : "2014,
- '@timestamp' : "1234567"
- '@date_path' : "2014/01/14"
- '@date_slug' : "2014-01-14,
- '@datetime_slug' : "2013-12-12-06-08-52"
- '@uid': 'dasfas-23r32-sad-3sadf-sdf"

**NOTE** ALL TIME VARIABLES ARE CURRENT UTC.

For instance,

``` python
import s3pyo

obj = {"key": "value"}
filepath = 'test/{key}/{@date_path}/{@uid}.json.gz'

plz = s3pyo.please('s3://my-bucket')
fp = plz.put(obj, filepath, **obj)
print fp
# >>> 's3://my-bucket/value/2014/08/25/3225-sdsa-35235-asdfas-235.json.gz'

```



### Serialization

By default, you can serialize / deserialize objects to / from `json.gz`,
`json`, or `gz` (set with `serialize` via `s3pyo.please`. However, you can also inherit from the core `s3pyo.S3` class and overwrite the `serialize` and `deserialize` methods.

```python

from s3pyo import S3

class SqlAlchemyToS3(S3):

def serialize(self, obj):
return "Do something hipster here."

def deserialize(self, string):
return "Undo it."

plz = SqlAlchemyToS3('s3://bucket')
print plz.get('s3://bucket/file.mycoolformat')
# >>> `A SqLAlchemy Model`
```

_I can assure you they will never get me onto one of those dreadful buckets._

Project details


Download files

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

Source Distribution

s3pyo-0.0.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

s3pyo-0.0.2.macosx-10.10-intel.exe (70.2 kB view details)

Uploaded Source

File details

Details for the file s3pyo-0.0.2.tar.gz.

File metadata

  • Download URL: s3pyo-0.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for s3pyo-0.0.2.tar.gz
Algorithm Hash digest
SHA256 53010b6dd89378a58af0532aecd69a21c127f0c7d84c507a37720a474421db59
MD5 572c61c81a2dea6345e3dac0f5121448
BLAKE2b-256 f875b1db030effdfbae2c59ef530a7098d6a3fb1ab2db0e5d90eba1e378e0bb2

See more details on using hashes here.

File details

Details for the file s3pyo-0.0.2.macosx-10.10-intel.exe.

File metadata

File hashes

Hashes for s3pyo-0.0.2.macosx-10.10-intel.exe
Algorithm Hash digest
SHA256 87f7fff09da398f2d03e41e55230e17af6a38b4d741b4a831ea30e9a37a29ebc
MD5 e2150c62eea78797a407fbadc383dddb
BLAKE2b-256 b2880996d1eef0a2b81e3a6b64d224a08ce7e5fef2f11cdffe1db5b7cf86519f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page