Skip to content

Mnemonic (Class)

A BIP-39 mnemonic seed phrase.

Mnemonic phrases (also called seed phrases or recovery phrases) are human-readable representations of cryptographic seeds used for HD wallet generation.

entropy property writable

entropy: str

The entropy bytes as a hex string.

phrase property writable

phrase: str

The mnemonic phrase as a space-separated word string.

__new__

__new__(phrase: str, language: str | Language = English) -> Mnemonic

Create a mnemonic from an existing phrase.

PARAMETER DESCRIPTION
phrase

The mnemonic phrase string.

TYPE: str

language

Optional language for the phrase (default: English).

TYPE: str | Language DEFAULT: English

RETURNS DESCRIPTION
Mnemonic

A new Mnemonic instance.

TYPE: Mnemonic

RAISES DESCRIPTION
Exception

If the phrase is invalid.

random staticmethod

random(word_count: Optional[int] = None) -> Mnemonic

Generate a random mnemonic phrase.

PARAMETER DESCRIPTION
word_count

Number of words (12, 15, 18, 21, or 24). Default: 24.

TYPE: Optional[int] DEFAULT: None

RETURNS DESCRIPTION
Mnemonic

A new random mnemonic.

TYPE: Mnemonic

RAISES DESCRIPTION
Exception

If the word count is invalid.

to_seed

to_seed(password: Optional[str] = None) -> str

Convert the mnemonic to a seed for key derivation.

PARAMETER DESCRIPTION
password

Optional passphrase for additional security.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
str

The seed as a hex string.

TYPE: str

Note

The same mnemonic with different passwords produces completely different seeds (and thus different wallets).

validate staticmethod

validate(phrase: str, language: str | Language = English) -> bool

Validate a mnemonic phrase.

PARAMETER DESCRIPTION
phrase

The mnemonic phrase to validate.

TYPE: str

language

Optional language for validation (default: English).

TYPE: str | Language DEFAULT: English

RETURNS DESCRIPTION
bool

True if the phrase is valid, False otherwise.

TYPE: bool