Skip to main content

pyargon2

Simultaneously the simplest and most powerful implementation of Argon2 in Python
Proudly serving the community since 2020

Installation

pip install pyargon2

Please note that for security reasons, pyargon2 does not ship with pre-compiled binaries (Wheels) available on PyPi. This is to ensure that what is shown in this repository is what is installed on target machines. Therefore, during the installation process, the underlying Argon2 C implementation will be compiled from source automatically for your OS and architecture. This will add a short delay to the installation process, but is worthwhile in order to maintain guarantees and verifiability with respect to what is being installed on target machines.

Basic Usage

The hash function supports basic password hashing using the Argon2id variant and mandates password and salt strings. The resulting hash returned is hex encoded.

from pyargon2 import hash

password = 'a strong password'
salt = 'a unique salt'
hex_encoded_hash = hash(password, salt)

The default parameters aim to generate hashes in around 0.5 seconds and are targeted at a machine housing a CPU with 4 cores and at least 4GB of RAM. If timing differs significantly on your machine, adjust the parameters using the advanced options below. Remember password hashing should be slow for security so don't optimise for speed!

Advanced Usage

Function Choices

pyargon2 contains two functions for hashing. Namely, hash and hash_bytes. These two functions differ in their input types only. This is explained in detail in the subsequent sections. To minimise input dependent hashing performance, dynamic type checking is not used in pyargon2. Instead, dedicated functions are exposed to deal with hashing strings or byte arrays separately. As such, one should ensure that they hash passwords, salts and peppers of the same type and then pick the corresponding function in pyargon2 as appropriate.

Function Parameters

The hash and hash_bytes functions take in the following parameters:

Positional
  • password : A string (or byte array when using hash_bytes) representing a password.
  • salt : A string (or byte array when using hash_bytes) representing a unique salt.
Keyword (Optional)
  • pepper : A secret string (or byte array when using hash_bytes) to fold into the hash of the password.
  • hash_len : The length in bytes of the resulting hash.
  • time_cost : The number of iterations to perform.
  • memory_cost : The number of kibibytes in memory to utilise.
  • parallelism : The number of independent computations chains (lanes) to run.
  • flags : Flags to determine which fields are securely wiped.
  • variant : Argon2 algorithm variant ('i', 'd', or 'id').
  • version : Argon2 algorithm version number.
  • encoding : Encoding for the returned hash type ('raw', 'hex' or 'b64').

For assistance with parameter selection refer to RFC 9106, in particular "Chapter 4: Parameter Choice".

Function Exceptions

Exceptions generated by the underlying Argon2 hashing function are raised under the Argon2Error class which can be imported as follows:

from pyargon2 import Argon2Error

Metadata

Release files for pyargon2 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyargon2 1.1.2
File Size Uploaded
pyargon2-1.1.2.tar.gz 56.9 kB Details

Release files / pyargon2-1.1.2.tar.gz

Download URL pyargon2-1.1.2.tar.gz
Size 56.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e9d74d5a8cb18cb56b0aeb2b7122658beb65c1ee1c830025e7db00269d77807d
BLAKE2b-256 checksum
How to use checksums
312bd0ec8fcc1232cadb3ac947f70732d4c370f375d2d1aa569410d6be1531c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

1.1.2 This release

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.9.0

1 release file

0.2.8

1 release file

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