<p>You can take a look at this function that I am using to work with Hierarchical Deterministic Wallets in PyCardano. If the mnemonic file does not exist, it generates a new one and saves it to disk, and if it exists, it is using it.</p>
<pre><code>def wallet_from_mnemonic(mnemonic_file: str, address_count: int = 1) -&gt; dict:
    &quot;&quot;&quot;Generate the wallet from a mnemonic phrase existing in a file on disk.
    If the mnemonic file does not exist, generate a new mnemonic and save it.
    &quot;&quot;&quot;
    try:
        with open(mnemonic_file, &quot;r&quot;) as f:
            mnem = f.read().strip()
    except FileNotFoundError:
        mnem = HDWallet.generate_mnemonic()
        with open(mnemonic_file, &quot;w&quot;) as f:
            f.write(mnem)
    hdw = HDWallet.from_mnemonic(mnem)

    &quot;&quot;&quot;
    Derive the staking key
    &quot;&quot;&quot;
    stk = hdw.derive_from_path(stake_derivation_path)
    stk_skey = StakeExtendedSigningKey.from_hdwallet(stk)
    stk_vkey = StakeExtendedVerificationKey.from_signing_key(stk_skey)

    &quot;&quot;&quot;
    Derive the first payment address
    &quot;&quot;&quot;
    wlts = {}
    for i in range(address_count):
        payment = hdw.derive_from_path(payment_derivation_path[0:-1] + str(i))
        p_skey = ExtendedSigningKey.from_hdwallet(payment)
        p_vkey = 
PaymentExtendedVerificationKey.from_signing_key(p_skey)
        p_addr = Address(p_vkey.hash(), stk_vkey.hash(), network)
        wlts[i] = {
            'addr': p_addr,
            'skey': p_skey,
            'vkey': p_vkey
        }
    return wlts
</code></pre>

CC BY-SA 4.0
2023-09-26T13:22:52.607Z
great I'll try it. Even if I however generated new wallets with more info already
Mik_A
CC BY-SA 4.0
2023-09-25T14:54:08.920Z
2023-09-25T14:54:08.920Z
George - APEX Stake Pool
<p>found nice examples generating verification keys and payment keys but I don't get to same time generate the seed phrase. Without the seed phrase I cannot open the wallet in a hot wallet to view it and so forth.</p>
<p>I simply do not understand the docs.
here is api docs
<a href="https://pycardano.readthedocs.io/en/latest/api/pycardano.crypto.html?highlight=seed%20phrase" rel="nofollow noreferrer">https://pycardano.readthedocs.io/en/latest/api/pycardano.crypto.html?highlight=seed%20phrase</a></p>

<wallet><python><seed-phrase>
pycardano library seed phrase
# pycardano library seed phrase

(Asked by: username_0 on 2023-09-23)

found nice examples generating verification keys and payment keys but I don't get to same time generate the seed phrase. Without the seed phrase I cannot open the wallet in a hot wallet to view it and so forth.

I simply do not understand the docs.
here is api docs
<https://pycardano.readthedocs.io/en/latest/api/pycardano.crypto.html?highlight=seed%20phrase>

**Tags:** wallet, python, seed-phrase

---

## 1 answers

### Answer by username_1 on 2023-09-25. Score: 1

You can take a look at this function that I am using to work with Hierarchical Deterministic Wallets in PyCardano. If the mnemonic file does not exist, it generates a new one and saves it to disk, and if it exists, it is using it.
def wallet_from_mnemonic(mnemonic_file: str, address_count: int = 1) -> dict:
    """Generate the wallet from a mnemonic phrase existing in a file on disk.
    If the mnemonic file does not exist, generate a new mnemonic and save it.
    """
    try:
        with open(mnemonic_file, "r") as f:
            mnem = f.read().strip()
    except FileNotFoundError:
        mnem = HDWallet.generate_mnemonic()
        with open(mnemonic_file, "w") as f:
            f.write(mnem)
    hdw = HDWallet.from_mnemonic(mnem)

    """
    Derive the staking key
    """
    stk = hdw.derive_from_path(stake_derivation_path)
    stk_skey = StakeExtendedSigningKey.from_hdwallet(stk)
    stk_vkey = StakeExtendedVerificationKey.from_signing_key(stk_skey)

    """
    Derive the first payment address
    """
    wlts = {}
    for i in range(address_count):
        payment = hdw.derive_from_path(payment_derivation_path[0:-1] + str(i))
        p_skey = ExtendedSigningKey.from_hdwallet(payment)
        p_vkey = 
PaymentExtendedVerificationKey.from_signing_key(p_skey)
        p_addr = Address(p_vkey.hash(), stk_vkey.hash(), network)
        wlts[i] = {
            'addr': p_addr,
            'skey': p_skey,
            'vkey': p_vkey
        }
    return wlts

> **Comments:**
> **username_0**: great I'll try it. Even if I however generated new wallets with more info already  

---

