Skip to main content

requests-http-signature is a Requests authentication plugin (requests.auth.AuthBase subclass) implementing the IETF HTTP Signatures draft RFC. It has no required dependencies outside the standard library. If you wish to use algorithms other than HMAC (namely, RSA and ECDSA algorithms specified in the RFC), there is an optional dependency on cryptography.

Installation

$ pip install requests-http-signature

Usage

import requests
from requests_http_signature import HTTPSignatureAuth

preshared_key_id = 'squirrel'
preshared_secret = 'monorail_cat'
url = 'http://example.com/path'

requests.get(url, auth=HTTPSignatureAuth(key=preshared_secret, key_id=preshared_key_id))

By default, only the Date header is signed (as per the RFC) for body-less requests such as GET. The Date header is set if it is absent. In addition, for requests with bodies (such as POST), the Digest header is set to the SHA256 of the request body and signed (an example of this appears in the RFC). To add other headers to the signature, pass an array of header names in the header keyword argument.

In addition to signing messages in the client, the class method HTTPSignatureAuth.verify() can be used to verify incoming requests:

def key_resolver(key_id, algorithm):
    return 'monorail_cat'

HTTPSignatureAuth.verify(request, key_resolver=key_resolver)

Asymmetric key algorithms (RSA and ECDSA)

For asymmetric key algorithms, you should supply the private key as the key parameter to the HTTPSignatureAuth() constructor as bytes in the PEM format:

with open('key.pem', 'rb') as fh:
    requests.get(url, auth=HTTPSignatureAuth(algorithm="rsa-sha256", key=fh.read(), key_id=preshared_key_id))

When verifying, the key_resolver() callback should provide the public key as bytes in the PEM format as well:

License

Licensed under the terms of the Apache License, Version 2.0.

https://travis-ci.org/kislyuk/requests-http-signature.png https://codecov.io/github/kislyuk/requests-http-signature/coverage.svg?branch=master https://img.shields.io/pypi/v/requests-http-signature.svg https://img.shields.io/pypi/l/requests-http-signature.svg https://readthedocs.org/projects/requests-http-signature/badge/?version=latest

Release files for requests-http-signature 0.1.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 requests-http-signature 0.1.0
File Size Uploaded
requests-http-signature-0.1.0.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for requests-http-signature 0.1.0
File Interpreter ABI Platform
requests_http_signature-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 11.1 kB

Release files / requests-http-signature-0.1.0.tar.gz

Download URL requests-http-signature-0.1.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0e39d928469e6f1411e3bffca74a280ac9375d4fa5bf03552974f0ba4ff4c37a
BLAKE2b-256 checksum
How to use checksums
10183744e7bc8b846dc7f4718ad189261f2eb47a70190a2f69a877f2ab51a77c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release files / requests_http_signature-0.1.0-py2.py3-none-any.whl

Download URL requests_http_signature-0.1.0-py2.py3-none-any.whl
Size 4.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f41debf21abaa8bb5ec6c367ddc6a5003d98ef4df21afb20f90f2195bd22c7d3
BLAKE2b-256 checksum
How to use checksums
45c2dd86e89f8f4fb6cc0028793f725bd536757b630c5734621f72b94b55ef53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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