EscherPython - HTTP request signing lib 
Escher helps you creating secure HTTP requests (for APIs) by signing HTTP(s) requests. It's both a server side and client side implementation. The status is work in progress.
The algorithm is based on Amazon's AWS Signature Version 4, but we have generalized and extended it.
More details are available at escherauth.io.
Signing a request
Escher works by calculating a cryptographic signature of your request, and adding it (and other authentication information) to said request.
Usually you will want to add the authentication information to the request by appending extra headers to it.
from escherauth import Escher
request = {
'method': 'POST',
'url': '/',
'host': 'example.com',
'headers': [
['X-Foo', 'bar'],
],
'body': '{"this_is": "a_request_body"}',
}
escher = Escher('YOUR_ACCESS_KEY_ID', 'YOUR SECRET', 'example/credential/scope')
signed_request = escher.sign_request(request)
from pprint import pprint
pprint(signed_request)
Signing a Requests request:
import requests
from escherauth import EscherRequestsAuth
auth = EscherRequestsAuth('YOUR_ACCESS_KEY_ID', 'YOUR SECRET', 'example/credential/scope')
response = requests.post('https://httpbin.org/post', json={'this_is': 'a_request_body'}, auth=auth)
from pprint import pprint
pprint(response.json())
Presigning a URL
In some cases you may want to send authenticated requests from a context where you cannot modify the request headers, e.g. when embedding an API generated iframe.
You can however generate a presigned URL, where the authentication information is added to the query string.
from escherauth import Escher
escher = Escher('YOUR_ACCESS_KEY_ID', 'YOUR SECRET', 'example/credential/scope')
presigned_url = escher.presign_url('http://example.com/', expires=300)
print(presigned_url)
Validating a request
You can validate a request signed by the methods described above. For that you will need a database of the access keys and secrets of your clients.
from escherauth import Escher, EscherException
escher = Escher('', '', 'example/credential/scope')
signed_request = {
'body': '{"this_is": "a_request_body"}',
'headers': [
['Host', 'example.com'],
['X-Escher-Date', '20240227T121443Z'],
['X-Escher-Auth', 'ESR-HMAC-SHA256 Credential=YOUR_ACCESS_KEY_ID/20240227/example/credential/scope, SignedHeaders=host;x-escher-date, Signature=5febb099193b8e6c4027ff810e0faa5bc8a275efb46f2d5c1af8810f4332c4cb'],
],
'method': 'POST',
'url': '/',
}
key_db = {
'ACCESS_KEY_OF_CLIENT_1': 'SECRET OF CLIENT 1',
'ACCESS_KEY_OF_CLIENT_42': 'SECRET OF CLIENT 42',
}
try:
escher.authenticate(signed_request, key_db)
print('OK')
except EscherException as e:
print(f'The validation failed: {e}')
Metadata
Release files for escherauth 2.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 | Provenance | Actions |
|---|---|---|---|---|
| escherauth-2.0.1.tar.gz | 11.2 kB | Without provenance | Details for escherauth-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| escherauth-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for escherauth-2.0.1-py3-none-any.whl |
Total release size: 19.1 kB
Release files / escherauth-2.0.1.tar.gz
| Download URL | escherauth-2.0.1.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8606159335e6266b2df53e4c3e5d18ec0343d3de5679bba6f9266758300a0c80
|
|
BLAKE2b-256 checksum How to use checksums |
42bf91e5c2cd6df312bd47a4d92783728a1fffe87a37fb021f38772d51867e7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|
Release files / escherauth-2.0.1-py3-none-any.whl
| Download URL | escherauth-2.0.1-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf86f147c3e178d83a4122e8706c67a3d4313a2fedacf7125a45d3b976a9878d
|
|
BLAKE2b-256 checksum How to use checksums |
45445b0038f4e75bc22e61a716bc3ebd491239dafcba52e61dade69df322dd8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|
Security for escherauth 2.0.1
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.