Skip to main content

Signa

PyPi Version

Utility lib to create authorized requests for various services.

Supported services:

  • AWS S3
  • Digital Ocean Spaces
  • Yandex Object storage
  • Alibaba Cloud OSS

Currently in alpha, use with caution!

Install

pip install signa

Usage example

import os
import requests
import signa

AWS_S3_REGION = '...'
AWS_S3_BUCKET = '...'
AWS_S3_UPLOAD_ACCESS_KEY = '...'
AWS_S3_UPLOAD_SECRET_KEY = '...'

S3_SIGNA = signa.Factory(
    's3',
    region=AWS_S3_REGION,
    bucket=AWS_S3_BUCKET,
    payload='UNSIGNED-PAYLOAD',
    auth={
        'access_key': AWS_S3_UPLOAD_ACCESS_KEY,
        'secret_key': AWS_S3_UPLOAD_SECRET_KEY,
    })

CONTENT_TYPES = {
    '.jpg': 'image/jpeg',
    '.jpeg': 'image/jpeg',
    '.png': 'image/png',
    '.mp4': 'video/mp4',
    '.json': 'application/json',
}


def put_file(*, key=None, path_or_data=None, make_public=True,
             s3_signa=S3_SIGNA):
    """Put file to S3 with signa example. Return uploaded URL.
    """
    ext = os.path.splitext(key)[1]
    headers = {
        'content-type': CONTENT_TYPES.get(ext, 'application/octet-stream')
    }
    if make_public:
        headers['x-amz-acl'] = 'public-read'

    signed = s3_signa.new(method='PUT', key=key, headers=headers)

    if isinstance(path_or_data, str):
        path = path_or_data
        with open(path, 'rb') as data_fp:
            response = requests.put(signed['url'],
                                    headers=signed['headers'],
                                    data=data_fp)
    else:
        data = path_or_data
        response = requests.put(signed['url'],
                                headers=signed['headers'],
                                data=data)

    if response.status_code == 200:
        print('put_file: OK')
        return signed['url']

    return None

Metadata

Release files for signa 0.3.0

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

Source distribution (sdist)

Source distribution for signa 0.3.0
File Size Uploaded Provenance Actions
signa-0.3.0.tar.gz 7.7 kB Without provenance Details for signa-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for signa 0.3.0
File Interpreter ABI Platform Actions
signa-0.3.0-py3-none-any.whl Python 3 none any Details for signa-0.3.0-py3-none-any.whl

Total release size: 16.8 kB

Release files / signa-0.3.0.tar.gz

Download URL signa-0.3.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
81bec5ed8464d0876bb593a4c9376d49ecfff9e8a25178f00a348a7fe32ac335
BLAKE2b-256 checksum
How to use checksums
0d1926836e4dcce472ba83d9e8460118859985294f7f2c3879298b96d47f5aa3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

Release files / signa-0.3.0-py3-none-any.whl

Download URL signa-0.3.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43d74a7866b3be7402d5be9eb65c8ea10aa744dbdfbd8da6979bf326d8e18dfb
BLAKE2b-256 checksum
How to use checksums
eb4ba1370f3eb7fcc807905551b25a21684c3e0a73e3e2d8c68f0285cfe03029
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

Security for signa 0.3.0

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