Skip to main content

CLI for managing PostHog resources

Project description

piglet

A CLI for managing PostHog resources - feature flags, cohorts, dashboards, insights, and projects.

Note: This is not an official PostHog project. It is maintained by Cased.

Installation

uv tool install cased-piglet

Or with pip:

pip install cased-piglet

Configuration

Configuration can be provided via CLI options, environment variables, or config file (in that order of precedence).

Environment Variables

export POSTHOG_API_KEY="phx_your_key"
export POSTHOG_PROJECT_ID="12345"
export POSTHOG_HOST="us"  # optional, defaults to us

Config File

Create ~/.piglet/config.toml:

api_key = "phx_your_key"
project_id = 12345
host = "us"

Host Shortcuts

  • ushttps://us.posthog.com (default)
  • euhttps://eu.posthog.com
  • Or use a full URL for self-hosted: https://posthog.mycompany.com

Global Options

--api-key TEXT        PostHog personal API key
--host TEXT           PostHog host (us, eu, or full URL)
--project-id INTEGER  PostHog project ID
--json                Output as JSON
--plain               Output as plain tab-separated text

Commands

Feature Flags

piglet flags list                # List all flags
piglet flags list --active       # List only active flags
piglet flags list --inactive     # List only inactive flags
piglet flags get <id-or-key>     # Get flag by ID or key
piglet flags create --key my-flag --name "My Flag" --rollout-percentage 50
piglet flags update 123 --rollout-percentage 100
piglet flags update 123 --active
piglet flags update 123 --inactive
piglet flags delete 123          # Prompts for confirmation
piglet flags delete 123 --yes    # Skip confirmation

Cohorts

piglet cohorts list              # List all cohorts
piglet cohorts list --static     # List only static cohorts
piglet cohorts list --dynamic    # List only dynamic cohorts
piglet cohorts get 123           # Get cohort details
piglet cohorts create --name "My Cohort"
piglet cohorts create --name "Static Cohort" --static
piglet cohorts update 123 --name "New Name"
piglet cohorts delete 123

Dashboards

piglet dashboards list           # List all dashboards
piglet dashboards list --pinned  # List only pinned dashboards
piglet dashboards get 123        # Get dashboard details
piglet dashboards create --name "My Dashboard"
piglet dashboards update 123 --name "New Name" --pinned
piglet dashboards delete 123

Insights

piglet insights list             # List all insights
piglet insights list --saved     # List only saved insights
piglet insights list --favorited # List only favorited insights
piglet insights get <id-or-short-id>
piglet insights create --name "My Insight"
piglet insights update 123 --name "New Name"
piglet insights delete 123

Projects

piglet projects list             # List all projects
piglet projects get 123          # Get project details

Output Formats

# Rich table (default)
piglet flags list

# JSON output
piglet --json flags list

# Plain tab-separated (good for scripting)
piglet --plain flags list
piglet --plain flags list | cut -f2  # Extract just the keys

Examples

# Use EU cloud
piglet --host eu flags list

# Self-hosted instance
piglet --host https://posthog.mycompany.com flags list

# Override project ID
piglet --project-id 99999 flags list

# Create and immediately enable a flag at 100%
piglet flags create --key new-feature --rollout-percentage 100 --active

# Disable a flag
piglet flags update 123 --inactive

# Export all flags as JSON
piglet --json flags list > flags.json

Claude Code Plugin

A Claude Code plugin is available for natural language interaction with piglet:

/plugin marketplace add cased/claude-code-plugins
/plugin install piglet

Once installed, you can ask Claude things like:

  • "What feature flags do we have?"
  • "Create a flag called dark-mode with 50% rollout"
  • "Disable the beta-feature flag"
  • "List all cohorts"

License

MIT


Piglet

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

cased_piglet-0.1.0.tar.gz (944.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cased_piglet-0.1.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file cased_piglet-0.1.0.tar.gz.

File metadata

  • Download URL: cased_piglet-0.1.0.tar.gz
  • Upload date:
  • Size: 944.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for cased_piglet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 01a4f57ff061d88939c10a391541a76d9eb7275dab941cf4a4a10d5a06a39c11
MD5 63d5c646e71cf21132cc1d95b1420cf4
BLAKE2b-256 c47a7efa9fa8aae2d0ab6e3d5642c2f10b2e6c5dfb115bb7be79b19d4853c04d

See more details on using hashes here.

File details

Details for the file cased_piglet-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cased_piglet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for cased_piglet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3fe409be3fb697b66c1c91ef2974875b949ab8f988d680dc4e1ef6f6102c66f
MD5 e8b9d49b48cd9a33672bd7a842cdd50e
BLAKE2b-256 420943725666e2f95a6df80b0e93564f54f409165a717f74f51fc2c9a098f3e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page