CLI for operating Powerbase console workflows
Project description
powerbase-cli
Python CLI for automating Powerbase console operations, with a command shape designed for Openclaw and other LLM agents.
What It Covers
powerbase-cli mirrors the main console workflows with a user-mode auth model:
- browser login bridge for CLI use
- local session persistence and refresh
- config and context management
- organizations, databases, instances, branches
- SQL execution
- publish diff and publish run
- sandbox file operations
- sandbox agent provider config, chat, and login workflows
The CLI is optimized for agent use:
- stable command groups
--helpexplains parameter source and format--jsonis available for machine-readable output- context can be saved so later commands need fewer flags
Database model:
- default path:
powerbase instance createuses the managed Powerbase database flow - advanced path:
powerbase database create --dsn ...registers an existing external database connection for later use with--database-id powerbase database createdoes not provision a new physical database
Install And Run
Install from PyPI:
python -m pip install powerbase-cli
powerbase --help
From the repository root during development:
pip install -e .
Or run directly during development:
PYTHONPATH=src python3 -m powerbase_cli --help
Configuration Model
Values are resolved in this order:
- command flags
- environment variables
~/.config/powerbase/- built-in defaults
Default local files:
~/.config/powerbase/
config.toml
auth.json
context.json
Most users do not need environment variables.
Optional advanced overrides:
POWERBASE_ACCESS_TOKENandPOWERBASE_REFRESH_TOKENfor non-browser or pre-issued login flowsPOWERBASE_INSTANCE_ID,POWERBASE_ORG_ID, andPOWERBASE_BRANCHto prefill local contextPOWERBASE_CONFIG_DIRto isolate local state, for example in tests or E2E runsPOWERBASE_OUTPUTto default tojson
Authentication
Browser Login
The preferred flow is:
powerbase auth login
The CLI now includes a built-in base_url and anon_key default for this deployment. The test package also bundles this environment's self-signed CA certificate, so most users can start with browser login directly and only use flags or environment variables when overriding that default.
The bundled CA is a test-only convenience for the current self-signed deployment. After the console moves to a publicly trusted TLS certificate, remove the bundled CA fallback and package resource, then keep only the built-in base_url and anon_key defaults.
This will:
- request a CLI login session from Powerbase
- print a browser URL
- poll until browser approval or until
--timeoutelapses (default 300 seconds, five minutes) - save the resulting session to
~/.config/powerbase/auth.json
Use --timeout 0 to wait without a time limit. Use a larger value if users need more than five minutes to complete login.
If an agent or wrapper script is coordinating the workflow, it is still helpful
to tell the user: after browser approval, return to the current session so the
remaining steps can continue.
Manual Token Import
Use this when browser login is not available in the current agent environment:
powerbase auth token-set \
--access-token ACCESS_TOKEN \
--refresh-token REFRESH_TOKEN \
--expires-at 1760000000
Use --base-url or --anon-key here only when you intentionally want to override the built-in deployment defaults.
Check Auth State
powerbase auth status --json
Refresh A Saved Session
powerbase auth refresh --json
Context Workflow
For repeated agent workflows, save the current org, instance, and branch:
powerbase context use-org ORG_ID
powerbase context use-instance INSTANCE_ID
powerbase context use-branch main
powerbase context show --json
After that, many commands can omit --instance-id.
Common Workflows
Discover Resources
powerbase org list --json
powerbase database list --json
powerbase instance list --json
powerbase branch list --instance-id INSTANCE_ID --json
Create An Instance With The Managed Database Flow
This is the default and recommended path:
powerbase org list --json
powerbase instance create --name todo-app --org-id ORG_ID --json
instance create returns when provisioning starts, not necessarily when every
dependent resource is immediately readable. If instance get, branch list, or
sandbox commands briefly say the instance is missing or partial, retry after a
short wait.
Register And Reuse An External Database Connection
Use this only when you intentionally want the advanced bring-your-own-database flow:
powerbase database create --name todo-db --dsn "mysql://user:pass@host:3306/db" --db-type mysql --json
powerbase instance create --name todo-app --database-id DATABASE_ID --org-id ORG_ID --json
Notes for the advanced path:
powerbase database createregisters a DSN in Powerbase; it does not create a physical database server- DSN credentials are sensitive and are stored by the platform
- branch and preview workflows may require SeekDB-compatible database behavior, not just generic MySQL wire compatibility
- deleting a Powerbase database record does not delete the external database itself
Switch To An Instance And Branch
powerbase context use-instance INSTANCE_ID
powerbase branch switch feature/demo --instance-id INSTANCE_ID --json
powerbase context use-branch feature/demo
When you create a branch with a name like feature/demo, later delete or SQL
commands should prefer the normalized slug returned by the API, such as
feature-demo, instead of assuming the original input string is still valid.
Run SQL
Inline SQL:
powerbase sql run --instance-id INSTANCE_ID --branch main --sql "SELECT 1" --json
From a file:
powerbase sql run --instance-id INSTANCE_ID --sql-file ./query.sql --json
Publish
powerbase publish diff --instance-id INSTANCE_ID --json
powerbase publish run --instance-id INSTANCE_ID --json
Sandbox Files
powerbase sandbox files tree --instance-id INSTANCE_ID --root / --json
powerbase sandbox files read --instance-id INSTANCE_ID /src/app.tsx --json
powerbase sandbox files upload --instance-id INSTANCE_ID ./local.txt --target-path /tmp --json
Sandbox Agent Providers
powerbase agent providers --instance-id INSTANCE_ID --json
powerbase agent status --instance-id INSTANCE_ID --provider cursor --json
powerbase agent login-url --instance-id INSTANCE_ID --provider cursor --json
Sandbox Agent Chat And Config
Send one prompt to the sandbox agent and stream events as JSONL:
powerbase branch switch feature/demo --instance-id INSTANCE_ID --json
powerbase agent chat \
--instance-id INSTANCE_ID \
--provider cursor \
--message "Build a todo app with create, complete, and delete actions." \
--stream-jsonl
agent chat follows the sandbox's current branch for the automatic preview build. Use
powerbase branch switch ... first when you want the generated preview to land on a
feature branch. powerbase context use-branch ... only changes the local default value;
it does not switch the remote sandbox by itself.
Read and update opencode provider config:
powerbase agent opencode-config get --instance-id INSTANCE_ID --json
powerbase agent opencode-config set --instance-id INSTANCE_ID --provider anthropic --api-key API_KEY --json
powerbase agent opencode-config delete --instance-id INSTANCE_ID --provider anthropic --json
Replace the sandbox opencode.json file:
powerbase agent opencode-json set --instance-id INSTANCE_ID --file ./opencode.json --json
Openclaw Usage Notes
When Openclaw or another LLM agent uses powerbase:
- prefer
--jsonon all commands - run discovery commands before write operations
- set context for long multi-step tasks
- use
auth statusbefore workflows that assume login - use
auth token-setif browser login is not practical in the current environment - remember that
--jsonoverrides a savedconfig output textsetting for that command
Recommended agent sequence:
powerbase auth status --json- If unauthenticated, run
powerbase auth loginorpowerbase auth token-set powerbase context show --json- If no instance is selected, run
powerbase instance list --json - If no suitable instance exists, prefer
powerbase instance create --name ... --org-id ... --json - Use
powerbase database ...only for the advanced bring-your-own-database path - Set context with
powerbase context use-instance ... - If you want the sandbox agent preview on a non-main branch, run
powerbase branch switch ... - Continue with
branch,sql,publish,sandbox files, oragentcommands
Testing
Run the full CLI test suite:
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=src python3 -m unittest discover -s tests -v
Compile the modules:
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=src python3 -m py_compile src/powerbase_cli/*.py
Project Skill
A project skill for Cursor/Openclaw-style agent usage lives in:
./.cursor/skills/powerbase-cli-openclaw/SKILL.md
Design and auth review notes live in:
./docs/console-cli-plan.md
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file powerbase_cli-0.1.0.tar.gz.
File metadata
- Download URL: powerbase_cli-0.1.0.tar.gz
- Upload date:
- Size: 32.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f9fed9a1ec5919e9bd60448926661596af0102f3d7d7d608875082d820dbf55
|
|
| MD5 |
4080416c2aab5a8fe307b918e6716433
|
|
| BLAKE2b-256 |
7e1bcf5a3a312f497c3b7cfc0c34a804e12bab089dd370fc9bc81fa86a370a14
|
File details
Details for the file powerbase_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: powerbase_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
011dc9828245fe3a81df9861db7ea7da45cb5970904f1303ca9d68f6e36c3b10
|
|
| MD5 |
7891a550f6bc1f2514bacd094b7925f0
|
|
| BLAKE2b-256 |
e950a482ea0237fc7735bd4715342979d9c215f98d1e021082ec5d58bed082d1
|