Helpers
various helpers from nic gist
from nicHelper.
Install
pip install nicHelper
How to use
add method to a class
class A:
pass
@add_method(A)
def printHello(self):
print('hello')
A().printHello()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-33c418d667e0> in <module>
1 class A:
2 pass
----> 3 @add_method(A)
4 def printHello(self):
5 print('hello')
NameError: name 'add_method' is not defined
First, import the s3 module
import package
from importlib import reload
from s3bz.s3bz import S3
set up dummy data
bucket = 'pybz-test'
key = 'test.dict'
sampleDict = {'test': 'bool'}
USER = None
PW = None
save object
result = S3.save(key = key,
objectToSave = sampleDict,
bucket = bucket,
user=USER,
pw = PW,
accelerate = True)
print(('failed', 'success')[result])
success
check if an object exist
result = S3.exist('', bucket, user=USER, pw=PW, accelerate = True)
print(('doesnt exist', 'exist')[result])
exist
load object
result = S3.load(key = key,
bucket = bucket,
user = USER,
pw = PW,
accelerate = True)
print(result[0])
{'ib_prcode': '10932', 'ib_brcode': '1003', 'ib_cf_qty': '473', 'new_ib_vs_stock_cv': '391'}
presign download object
url = S3.presign(key=key,
bucket=bucket,
expiry = 1000,
user=USER,
pw=PW)
print(url)
https://pybz-test.s3-accelerate.amazonaws.com/test.dict?AWSAccessKeyId=AKIAVX4Z5TKDVNE5QZPQ&Signature=6PfnHRYWc9xyk4oshrSECL5Eeyw%3D&Expires=1604392828
testing signed link
from s3bz.s3bz import Requests
result = Requests.getContentFromUrl(url)
File operations
save
inputPath = '/tmp/tmpFile.txt'
key = 'tmpFile'
downloadPath = '/tmp/downloadTmpFile.txt'
with open(inputPath , 'w')as f:
f.write('hello world')
S3.saveFile(key =key ,path = inputPath,bucket = bucket)
load
S3.loadFile(key= key , path = downloadPath, bucket = bucket)
with open(downloadPath, 'r') as f:
print(f.read())
hello world
Metadata
Release files for nicHelper 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nicHelper-0.0.1.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nicHelper-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.3 kB
Release files / nicHelper-0.0.1.tar.gz
| Download URL | nicHelper-0.0.1.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02b8a2490f7bce17994f6a83510ca6b260ae8be271b2060a0dd53f89cc77ef13
|
|
BLAKE2b-256 checksum How to use checksums |
6f0d5ca751c3f7e8e60c353deb692e042f61aac7f7f3ad6d4a9a30465550921f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
|
Release files / nicHelper-0.0.1-py3-none-any.whl
| Download URL | nicHelper-0.0.1-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f05be6fbd932bedfab647bf0b2b4d0615346515e773e9fb0f37ded2987fc848
|
|
BLAKE2b-256 checksum How to use checksums |
ef3bca3424f3bb5d79e51503258323fa61b56049a64abba6247ea761ec8a6df7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
|