pyHIBP (pyHave I Been Pwned)
A Python interface to Troy Hunt's 'Have I Been Pwned?' (HIBP) public API. A full reference to the API specification can be found at the HIBP API Reference.
This module detects when the rate limit of the API has been hit, and raises a RuntimeError when the limit is exceeded, or when another API-defined error condition is encountered based on the submitted data. When data is found from a call, the data returned will be in the format as retrieved from the endpoint, documented in the return-type information for the relevant function.
Note that the pwnedpasswords API backend does not have a rate limit. If you are intending to bulk-query passwords or
hashes, you should consider downloading the raw data files accessible via the Pwned Passwords page.
Installing
$ pip install pyhibp
Example usage
For an interactive example, check out the Jupyter Notebook for pyhibp,
as well as pyhibp.pwnedpasswords.
import pyhibp
from pyhibp import pwnedpasswords as pw
# Required: A descriptive user agent must be set describing the application consuming
# the HIBP API
pyhibp.set_user_agent(ua="Awesome application/0.0.1 (An awesome description)")
# Check a password to see if it has been disclosed in a public breach corpus
resp = pw.is_password_breached(password="secret")
if resp:
print("Password breached!")
print("This password was used {0} time(s) before.".format(resp))
# Get data classes in the HIBP system
resp = pyhibp.get_data_classes()
# Get all breach information
resp = pyhibp.get_all_breaches()
# Get a single breach
resp = pyhibp.get_single_breach(breach_name="Adobe")
# An API key is required for calls which search by email address
# (so get_pastes/get_account_breaches)
# See <https://haveibeenpwned.com/API/Key>
HIBP_API_KEY = None
if HIBP_API_KEY:
# Set the API key prior to using the functions which require it.
pyhibp.set_api_key(key=HIBP_API_KEY)
# Get pastes affecting a given email address
resp = pyhibp.get_pastes(email_address="test@example.com")
# Get breaches that affect a given account
resp = pyhibp.get_account_breaches(account="test@example.com", truncate_response=True)
Developing
In order to ensure we have a consistent and repeatable development environment
we use a virtual environment, namely pipenv.
To develop or test, execute the following:
# Install the prerequisite virtual environment provider
$ pip install pipenv
# Initialize the pipenv environment and install the module within it
$ make dev
# To run PEP8, tests, and check the manifest
$ make tox
Other commands can be found in the Makefile.
Goals
- Synchronize to the latest HIBP API(s), implementing endpoint accessing functions where it makes sense. For instance, in the interest of security, the ability to submit a SHA-1 to the Pwned Passwords endpoint is not implemented. See "Regarding password checking" below for further details.
- For breaches and pastes, act as an intermediary; return the JSON as received from the service.
Regarding password checking
- For passwords, the option to supply a plaintext password to check is provided as an implementation convenience.
- For added security,
pwnedpasswords.is_password_breached()only transmits the first five characters of the SHA-1 hash to the Pwned Passwords API endpoint; a secure password will remain secure without disclosing the full hash.
Metadata
Release files for pyhibp 4.2.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 | Actions |
|---|---|---|---|---|
| pyhibp-4.2.0.tar.gz | 32.1 kB | Without provenance | Details for pyhibp-4.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyhibp-4.2.0-py3-none-any.whl | Python 3 | none | any | Details for pyhibp-4.2.0-py3-none-any.whl |
Total release size: 52.9 kB
Release files / pyhibp-4.2.0.tar.gz
| Download URL | pyhibp-4.2.0.tar.gz |
|---|---|
| Size | 32.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
825c383e0ac43ac3438dad82e5ddb45773754fbb1b5c3b8ac56669483f2c67ed
|
|
BLAKE2b-256 checksum How to use checksums |
3a4a2bebc8a6f3230b0b0c39aae4cd05eed23cdb9ccf5914e08277f443a66c4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
|
Release files / pyhibp-4.2.0-py3-none-any.whl
| Download URL | pyhibp-4.2.0-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4fd8096eef5d840f5144fbfe66a07a5b984c12e4cf4936caea879106f18222ec
|
|
BLAKE2b-256 checksum How to use checksums |
fe4d581e025f8011c6f9f7beb06ad57fc9cfc7dcb994b37514551d0f412d2948
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
|
Security for pyhibp 4.2.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.