python-basicauth
A dead simple HTTP basic auth encoder and decoder. Why? Because HTTP should be drop dead easy... That's why.
Install
To install python-basicauth, simply run pip install basicauth and
you'll get the latest version installed automatically.
Usage
To generate an encoded basic auth string:
>>> from basicauth import encode
>>> username, password = 'rdegges', 'omghax!!!'
>>> encoded_str = encode(username, password)
>>> print encoded_str
'Basic cmRlZ2dlczpvbWdoYXglMjElMjElMjE='
To decode an encoded basic auth string:
>>> from basicauth import decode
>>> encoded_str = 'Basic cmRlZ2dlczpvbWdoYXglMjElMjElMjE=' # From the example above.
>>> username, password = decode(encoded_str)
>>> print (username, password)
('rdegges', 'omghax!!!')
We can also decode the encoded string directly:
>>> from basicauth import decode
>>> encoded_str = 'cmRlZ2dlczpvbWdoYXglMjElMjElMjE=' # From the example above.
>>> username, password = decode(encoded_str)
>>> print (username, password)
('rdegges', 'omghax!!!')
And if there are errors:
>>> from basicauth import decode, DecodeError
>>> encoded_str = 'lol omg cmRlZ2dlczpvbWdoYXglMjElMjElMjE=' # Invalid encoded string.
>>> username, password = decode(encoded_str)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "basicauth/__init__.py", line 49, in decode
raise DecodeError
basicauth.DecodeError
NOTE: The HTTP Basic Authentication spec
does NOT allow you to include any colon characters (:) in the username
field. Colons are allowed in the password field -- but that's it.
Tests
Want to run the tests? No problem:
$ git clone https://github.com/rdegges/python-basicauth.git
$ cd python-basicauth
$ pip install -e .
...
$ python -m unittest
..............
----------------------------------------------------------------------
Ran 14 tests in 0.103s
OK
Metadata
Release files for basicauth 1.0.0
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 | |
|---|---|---|---|---|
| basicauth-1.0.0.tar.gz | 3.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| basicauth-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.3 kB
Release files / basicauth-1.0.0.tar.gz
| Download URL | basicauth-1.0.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4739db0a8bd146702c3501afda172e66b51ebafc15ee65adbecb86b9ee0d51b
|
|
BLAKE2b-256 checksum How to use checksums |
3e38561378a529cc63303bb1e02c44801dda277b634169cbb1b86c0a68431e5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.1
|
Release files / basicauth-1.0.0-py3-none-any.whl
| Download URL | basicauth-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e6eb3deb883b1fce552e25b6a97083e1b5ab28771b3d7c2b76c5b6ae1cc4da7
|
|
BLAKE2b-256 checksum How to use checksums |
52b55bb9477a6a0b4fe88d2849858e150f07481200d5b4b4c789a39bd567e5b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.1
|
Security for basicauth 1.0.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.