Skip to main content

helper-auth on PyPI

This Python library provides the HelperAuth class whose objects are intended to be used as custom authentication handlers in conjunction with the Requests library, as suggested in its documentation.

Installation

pip install helper-auth

Usage

Suppose you have an existing GitHub personal access token, and a Git credential helper already set up for Git to authenticate to GitHub using this token as the password. This helper prints the following to standard output:

$ git credential-github
username=YOUR_GITHUB_USERNAME
password=YOUR_GITHUB_TOKEN

You want to use the same token to make GitHub API calls using the Requests library. The API expects the field Authorization: Bearer YOUR_GITHUB_TOKEN in your request's headers.

You can use HelperAuth with its default settings:

import requests
from helper_auth import HelperAuth

auth = HelperAuth("git credential-github")

response = requests.get("https://api.github.com/user", auth=auth)

Specifying the helper command

The helper command can be specified as one or more positional arguments:

auth = HelperAuth("helper")
auth = HelperAuth("helper", "--option", "arg")

As a shortcut, a command with command-line arguments can also be passed as single string (this form is used in the code snippet above):

auth = HelperAuth("helper --option arg")

In addition, the first positional argument can be a path-like object:

auth = HelperAuth(Path("helper"))
auth = HelperAuth(Path("helper"), "--option", "arg")

Caching the token

By default, a HelperAuth object never stores the value of the token in its internal state. Rather, the helper command is invoked each time the auth object is called. This is an intentional precaution (such that the token cannot be retrieved ex post by the introspection of the auth object) but it can also be unnecessarily expensive in situations where such precaution is not necessary and the auth object is to be called repeatedly, e.g. when making many simultaneous API calls.

You can override this behavior by passing cache_token=True to the constructor:

auth = HelperAuth("helper", cache_token=True)

The cached token can then be cleared anytime by calling

auth.clear_cache()

Metadata

Release files for helper-auth 0.8.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 helper-auth 0.8.0
File Size Uploaded
helper_auth-0.8.0.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for helper-auth 0.8.0
File Interpreter ABI Platform
helper_auth-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / helper_auth-0.8.0.tar.gz

Download URL helper_auth-0.8.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9102de42fa9c8f953a9558a1d4c79c9e9e061f4a637a59e0ea9b3c919b9a395a
BLAKE2b-256 checksum
How to use checksums
1a430e5abc9c94a4baf7874be44a803d1d705b06fa9ce1321b71dd2ca7239930
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.12.0 Linux/6.2.0-34-generic

Release files / helper_auth-0.8.0-py3-none-any.whl

Download URL helper_auth-0.8.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc0faccf4d12f6946984bd935e84a2f5081ea1381e19e783d1e96c73b9ef56ec
BLAKE2b-256 checksum
How to use checksums
9222c99a5c9f1c891d988ee71c89d08de44e0600ef0a7b3c20b9779537422093
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.12.0 Linux/6.2.0-34-generic

Release history Release notifications | RSS feed

This release

0.8.0 This release

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

0.1.0

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