Skip to main content

s3_connection

Description

A package that allows an easy connection to be made to an AWS S3 bucket, provided a valid AWS Access Key & AWS Secret Key are given (if no credentials are provided then only public buckets can be accessed). The package contains a class which stores the keys provided, and allows the user to read/write certain file formats to/from s3 buckets, through the use of class methods.

This package is essentially a wrapper for the s3fs package. It was created to be used as a subpackage in a wider project - PSUSANNX.

Package Functions

  • read_csv_from_s3()
  • write_csv_to_s3()
  • read_json_from_s3()
  • write_json_to_s3()
  • read_h5_from_s3()
  • write_h5_to_s3()
  • read_pkl_from_s3()
  • write_pkl_to_s3()

Installation

pip install s3_connection

Usage

# Import the class object from the package
from s3_connection.s3_conn_class import S3Connection

# Get some info about the class object
help S3Connection 

Once the class has been imported and you've read the help, you can create an instance of the class to allow you to interact with an s3 bucket in your aws account. Make sure you have the AWS Access key & the AWS secret key at hand.

# Create an instance of the class with AWS credentials
s3_conn = S3Connection(
    aws_access_key='<AWS-ACCESS-KEY>', 
    aws_secret_key='<AWS-SECRET-KEY>'
    )

The s3_conn object can now be used to call the functions to read/write to s3 buckets.

If you dont have access or secret keys and you want to access objects in public buckets, all you need to do is instantiate an instance of the class with no arguments, like this.

# Create an instance of the class with no credentials
s3_conn = S3Connection()

The read_from_s3 functions

The read___from_s3 functions just take the bucket name & object name as arguments then return the object.

# Use the s3_conn to read a csv from a bucket
pandas_df = s3_conn.read_csv_from_s3(
    bucket_name="<bucket-name>", 
    object_name="<path/to/file/within/bucket.csv>"
    )

The write_to_s3 functions

The write___to_s3 functions take the bucket name, object name & the data as arguments and return nothing.

If you already have a dataframe stored in a variable called existing_df then you can put it into an s3 bucket with the following function (index=False is automatically applied).

# Put the existing_df dataframe into the s3 bucket as a csv file
s3_conn.write_csv_to_s3(
    bucket_name="<bucket-name>", 
    object_name="<path/to/save/file.csv>",
    data=existing_df
    )

Notes

  • The package is quite restricted in what it can do, but it only needs to do things that are required by the parent project so there won't be much development.
  • A potential new feature to add to the package would be the ability to manage S3 resources, like create/delete buckets & objects from S3 from within the package.

Metadata

Release files for s3-connection 0.1.2

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

Source distribution (sdist)

Source distribution for s3-connection 0.1.2
File Size Uploaded Provenance Actions
s3_connection-0.1.2.tar.gz 4.7 kB Without provenance Details for s3_connection-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for s3-connection 0.1.2
File Interpreter ABI Platform Actions
s3_connection-0.1.2-py3-none-any.whl Python 3 none any Details for s3_connection-0.1.2-py3-none-any.whl

Total release size: 9.9 kB

Release files / s3_connection-0.1.2.tar.gz

Download URL s3_connection-0.1.2.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f839200be0814eec81961710ac69635030938462c866327048659cfc35c7d075
BLAKE2b-256 checksum
How to use checksums
6b76e3d289853daa0edb9e4b92c245e8f1e40d44a546b1f67617ed8334ecf381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

Release files / s3_connection-0.1.2-py3-none-any.whl

Download URL s3_connection-0.1.2-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a958f0ba39604cfe9f2fbc96a1443afb91cfeb489d2ba80583db1306890a96a9
BLAKE2b-256 checksum
How to use checksums
099cf1902d47ec73214f770cd8e7d4e626b9f27a6013e17792fac3a6724aa481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

Security for s3-connection 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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