Registry / auth-security / diceware

diceware

JSON →
library1.0.1pypypi✓ verified 24d ago

Diceware is a Python library and command-line tool for generating secure, memorable passphrases using the Diceware method. It generates passphrases by concatenating words randomly picked from wordlists. The library supports various sources of randomness, including Python's `SystemRandom` by default, and allows for different wordlists, including the EFF wordlist. It also offers options for capitalization and special characters. The current version is 1.0.1, actively maintained with recent updates.

pip install diceware
INSTALL
IMPORT
SIG · DICEWARE
D
diceware
auth-securitypythonv1.0.1
Install
1.7s avg
Import
40ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.042s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.038s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_passphrase
from diceware import get_passphrase
The primary function for programmatic passphrase generation.

Generate a Diceware passphrase using the `get_passphrase` function by providing an `options` object that mimics `argparse.Namespace`. The example uses default settings for a 6-word passphrase with capitalized words and no special characters or delimiters, leveraging the EFF wordlist and `SystemRandom`.

from types import SimpleNamespace from diceware import get_passphrase # Mimic argparse options for programmatic use options = SimpleNamespace( num=6, # Number of words (default: 6) caps=True, # Capitalize words (default: True) specials=0, # Number of special characters (default: 0) delimiter="", # Delimiter between words (default: "") randomsource="system", # Source of randomness (default: "system") wordlist=["en_eff"], # Wordlist name(s) (default: "en_eff") infile=None # Optional custom input wordlist file descriptor ) passphrase = get_passphrase(options=options) print(passphrase)
diceware --version
Debug
Known issues
gotchaThe default randomness source (`SystemRandom`) is cryptographically strong, but the original Diceware method recommends using physical dice for maximum security, as computer-generated randomness can be susceptible to manipulation reports.
fix
For maximum security, consider generating passphrases using actual physical dice in combination with the Diceware wordlists, rather than relying solely on computer-generated randomness. The library provides a `RealDiceRandomSource` option for integration.
affects: All versions
gotchaWordlists whose number of entries is not a perfect power of the dice sides (e.g., 6^5=7776 for `en_eff`) may have some words 'cut' to fit, potentially reducing the overall entropy and making passphrases slightly easier to guess.
fix
To mitigate reduced entropy, prioritize using wordlists with entries that are a perfect power of the dice sides, or choose longer passphrases.
affects: All versions
gotchaIf a wordlist contains 'prefix codes' (where one word is a prefix of another, like 'air' and 'airport'), it can slightly reduce the number of unique combinations and thus the passphrase's entropy.
fix
When using custom wordlists, ensure they do not contain words that are prefixes of other words in the list to maintain maximum entropy.
affects: All versions
gotchaBy default, words are capitalized and no delimiter is used. If both capitalization is disabled (`--no-caps`) and no delimiter is used, the passphrase entropy might be slightly reduced in rare cases where concatenated words could be parsed ambiguously (e.g., 'inputclammy' vs 'in put clam my').
fix
If disabling capitalization, it is recommended to use a clear delimiter between words (e.g., a space) to preserve entropy and readability.
affects: All versions
deprecatedWhile the library officially supports Python 2.7, using Python 2.x for security-sensitive applications is strongly discouraged due to its end-of-life status and lack of security updates.
fix
It is highly recommended to use Python 3.x (preferably 3.7+) for all new development and security-sensitive applications.
affects: <= 1.0.1
Errors
Common errors & fixes
FileNotFoundError: [Errno 2] No such file or directory: 'nonexistingfile'
This error occurs when the `diceware` command-line tool or library is instructed to use a custom wordlist file that does not exist at the specified path.
fix
Ensure the path to your custom wordlist file is correct and the file exists. If you intended to use a built-in wordlist, remove the `--infile` option.
ModuleNotFoundError: No module named 'diceware_utils'
This error typically arises when attempting to import an internal module (`diceware_utils`) directly, which is not part of the public API for the `diceware` library, or if there's a problem with the library's installation.
fix
Instead of importing internal modules, use the public API by importing the top-level `diceware` module and accessing its functions, for example, `from diceware import get_passphrase`.
SyntaxWarning: invalid escape sequence '\w'
This warning appears when running `diceware` with Python 3.12 or newer. It's caused by regular expression patterns within the library's code (e.g., in `diceware/wordlist.py`) that use non-raw strings with backslash escapes like `\w`, which Python 3.12 flags more strictly.
fix
This warning is usually addressed by the library maintainers in newer versions. As a user, you can often safely ignore this warning as it typically does not prevent the program from functioning, or update to the latest `diceware` version if a fix has been released.
Upgrade
Version history
1.0.1latest on PyPI · released Dec 24, 2024
Audit
Dependencies
PythonrequiredRuntime environment for the library, supports Python 2.7 and 3.4-3.12.
Agent activity
21 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
diceware — pip install diceware · libregistry