Skip to content
1Claw Academy
Curriculum/Integrations & Ecosystem3 minIntermediate · Lesson 1 of 11

Fetch a secret with the Python SDK

Install the oneclaw Python SDK, create a client, and print a secret from your vault.

The 1Claw Python SDK ships as the PyPI package oneclaw. You create a client with an API key, and it handles token exchange and refresh for you.

Concept

You need Python 3.9+ and a 1Claw API key from 1claw.co/settings/api-keys. A 1ck_ key is a user key, an ocv_ key is an agent key. Both work here.

  1. 1

    Create and activate a virtual environment.

    bash
    python3 -m venv .venv
    source .venv/bin/activate
  2. 2

    Install the SDK from PyPI.

    bash
    pip install oneclaw
  3. 3

    Export your API key and the vault ID that holds a secret. Replace 1ck_your_user_key with your 1ck_ key from Settings → API Keys. Use your vault UUID from 1claw vault list or the Foundations track.

    bash
    export ONECLAW_API_KEY=1ck_your_user_key
    export ONECLAW_VAULT_ID=your-vault-uuid
  4. 4

    Write the following script and save it as fetch_secret.py. It creates a client and reads one secret by path.

    python
    import os
    from oneclaw import create_client
    
    client = create_client(api_key=os.environ["ONECLAW_API_KEY"])
    vault_id = os.environ["ONECLAW_VAULT_ID"]
    
    secret = client.secrets.get(vault_id, "api-keys/openai")
    print(secret.data["value"])
  5. 5

    Create the secret if it doesn't already exist.

    bash
    1claw secret set api-keys/openai --vault $ONECLAW_VAULT_ID --value 'your-openai-key' --type api_key
  6. 6

    Run it. The fetched secret value prints to your terminal.

    bash
    python fetch_secret.py
Tip

Use create_client() inside a with block if you want the connection pool closed automatically when the script exits.

You now have a Python script that authenticates to 1Claw and prints a real secret pulled from your vault.

What this gives you, and what it does not. The Python client mirrors the TypeScript one in shape while following Python conventions, and the differences catch people who move between them.

  • Resource names differ deliberately. Python exposes client.vaults and snake_case methods; TypeScript uses client.vault and camelCase. Neither is a typo for the other.
  • The response envelope is the same. Calls return an object with data and error, so reading resp.data['value'] rather than treating the result as the value itself is the habit to build.
  • It does not manage your process environment. Fetching a secret gives you a value in memory; putting it into os.environ is a decision you are making, and one that widens its reach to every library in the process.
Tip

If you work in both languages, expect the pluralisation difference to bite once. client.vault in Python and client.vaults in TypeScript are both wrong, and both fail as attribute errors rather than anything descriptive.

Decide

A Python service fetches a database password at startup and needs it available to an ORM that reads DATABASE_URL. A colleague sets os.environ['DATABASE_URL'] right after the fetch, because the ORM expects it there.

What is the consequence worth raising?

Check your understanding

3 questions
1

What is the PyPI package name for the 1Claw Python SDK?

2

Which call retrieves a single secret by path?

3

What does an ocv_ prefixed key represent?