Skip to main content

Turn any website into an API. Graft scriptable access onto authenticated web services.

Project description

๐Ÿ”Œ graftpunk

Turn any website into an API.

Graft scriptable access onto authenticated web services.

Python 3.11+ License: MIT Code style: ruff Typed

Installation โ€ข Quick Start โ€ข CLI โ€ข Roadmap โ€ข Plugins


The Problem

That service has your dataโ€”but no API.

Your bank. Your 401k provider. Your insurance portal. Your HR system. They all have dashboards full of documents and data that belong to you, but no way to access them programmatically.

You're left with two options: click through the UI manually every time, or give up.

graftpunk gives you a third option.

The Solution

Log in once, script forever.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                                             โ”‚
โ”‚   1. LOG IN                2. CACHE                 3. SCRIPT               โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”‚
โ”‚   โ”‚   Browser   โ”‚         โ”‚  Encrypted  โ”‚         โ”‚   Python    โ”‚          โ”‚
โ”‚   โ”‚   Session   โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚   Storage   โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚   Script    โ”‚          โ”‚
โ”‚   โ”‚             โ”‚         โ”‚             โ”‚         โ”‚             โ”‚          โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ”‚
โ”‚                                                                             โ”‚
โ”‚   Log in manually         Session cached          Use the session          โ”‚
โ”‚   or with a plugin        with AES-128            to make requests         โ”‚
โ”‚                           encryption              like a real API          โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Once your session is cached, you can:

  • Make HTTP requests with your authenticated cookies
  • Reverse-engineer XHR calls from browser dev tools
  • Build CLI tools that feel like real APIs
  • Automate downloads of documents and data
  • Keep sessions alive with background daemons

What You Can Build

With graftpunk as your foundation, you can turn any authenticated website into a terminal-based interface:

# Download your latest bank statements
gp mybank statements --month january --output ./statements/

# Export transactions to CSV
gp mybank transactions --start 2024-01-01 --format csv > transactions.csv

# Check your 401k balance
gp my401k balance
# โ†’ Total: $142,857.32 (+2.4% this month)

# Download insurance documents
gp insurance documents --type claims --year 2024
# โ†’ Downloaded 12 documents to ./claims/

These aren't real APIsโ€”they're commands defined in graftpunk plugins that make the same XHR calls the website makes. To anyone watching, it looks like magic. To you, it's just automation.

Installation

pip install graftpunk

With cloud storage:

pip install graftpunk[supabase]   # Supabase backend
pip install graftpunk[s3]         # AWS S3 backend
pip install graftpunk[all]        # Everything

Quick Start

1. Cache a Session

from graftpunk import BrowserSession, cache_session

# Create a stealth browser (avoids bot detection)
session = BrowserSession(headless=False, use_stealth=True)

# Navigate to login page
session.driver.get("https://app.example.com/login")

# Log in manually in the browser window...
# (or automate it with a plugin)

# Cache the authenticated session
cache_session(session, "example")

2. Use It Like an API

from graftpunk import load_session_for_api

# Load your cached session (no browser needed)
api = load_session_for_api("example")

# Make authenticated requests
response = api.get("https://app.example.com/api/internal/documents")
documents = response.json()

for doc in documents:
    print(f"Downloading {doc['name']}...")
    content = api.get(doc['download_url']).content
    with open(doc['name'], 'wb') as f:
        f.write(content)

3. Keep It Alive

Sessions expire. graftpunk can keep them alive in the background:

# Your keepalive handler pings the site periodically
# to prevent session timeout

Features

Feature Why It Matters
๐Ÿฅท Stealth Mode Many sites block automation. graftpunk uses undetected-chromedriver and selenium-stealth to fly under the radar.
๐Ÿ”’ Encrypted Storage Sessions contain sensitive auth tokens. graftpunk encrypts everything with AES-128 (Fernet).
โ˜๏ธ Cloud Storage Access your sessions from anywhere. Store in Supabase or S3 for multi-machine workflows.
๐Ÿ”„ Keepalive Daemon Sessions expire. graftpunk can ping sites in the background to keep you logged in.
๐Ÿ”Œ Plugin System Define commands for reverse-engineered APIs. Python for complex logic, YAML for simple calls.
๐Ÿ› ๏ธ Beautiful CLI Manage sessions from the terminal with rich, colorful output.

CLI

$ gp --help

 ๐Ÿ”Œ graftpunk - turn any website into an API

 Graft scriptable access onto authenticated web services.
 Log in once, script forever.

 Quick start:
   gp list              Show all cached sessions
   gp show <name>       View session details
   gp clear <name>      Remove a session
   gp config            Show current configuration

Commands:
  list        List all cached sessions with status and metadata.
  show        Show detailed information about a cached session.
  clear       Remove cached session(s).
  export      Export session cookies to HTTPie format.
  import-har  Import HAR file and generate a plugin.
  config      Show current graftpunk configuration.
  plugins     List discovered plugins.
  version     Show graftpunk version and installation info.
  keepalive   Manage the session keepalive daemon.

List Sessions

$ gp list

              ๐Ÿ” Cached Sessions
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Session     โ”ƒ Domain           โ”ƒ   Status   โ”ƒ Cookies โ”ƒ Last Modified    โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ mybank      โ”‚ secure.mybank.comโ”‚  โ— active  โ”‚      18 โ”‚ 2024-01-15 09:30 โ”‚
โ”‚ my401k      โ”‚ participant.401k โ”‚  โ— active  โ”‚      12 โ”‚ 2024-01-14 14:22 โ”‚
โ”‚ insurance   โ”‚ portal.ins.com   โ”‚ โ—‹ expired  โ”‚       8 โ”‚ 2024-01-01 11:00 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

3 session(s) cached

Export to HTTPie

$ gp export mybank

โœ“ Exported to: ~/.config/httpie/sessions/secure.mybank.com/mybank.json

Usage:
  http --session=mybank https://secure.mybank.com/api/accounts

Import from HAR

Generate plugins from browser dev tools network captures:

$ gp import-har auth-flow.har --name mybank

Parsing HAR file: auth-flow.har
Found 127 HTTP requests

Site: mybank (secure.mybank.com)

Auth Flow Detected (3 steps):
  1. GET  /login (form page)
  2. POST /auth/login (credentials submitted)
  3. GET  /dashboard (authenticated, 2 cookies set)

Session Cookies: sessionId, authToken

API Endpoints (5 discovered):
  GET  /api/accounts
  GET  /api/transactions
  POST /api/transfer

Generated plugin: ~/.config/graftpunk/plugins/mybank.py

Options:

  • --format python|yaml - Output format (default: python)
  • --output PATH - Custom output path
  • --dry-run - Preview without writing
  • --no-discover-api - Skip API endpoint discovery

Configuration

Variable Default Description
GRAFTPUNK_STORAGE_BACKEND local Storage: local, supabase, or s3
GRAFTPUNK_CONFIG_DIR ~/.config/graftpunk Config and encryption key location
GRAFTPUNK_SESSION_TTL_HOURS 720 Session lifetime (30 days)
GRAFTPUNK_LOG_LEVEL INFO Logging verbosity

Roadmap

graftpunk is actively developed. Here's what's coming:

๐Ÿง™ Plugin Auto-Generation Wizard

Stop writing plugins by hand.

A built-in tool that watches you log in and generates the plugin code automatically:

$ gp wizard mybank
โ†’ Opening browser to capture auth flow...
โ†’ Log in normally (use dummy creds if you prefer)
โ†’ Capturing cookies, headers, session validation...
โ†’ Generated plugin: ~/.config/graftpunk/plugins/mybank.py

# Next time, login is automated:
$ gp login mybank

๐Ÿ“š Example Plugins

Templates and examples for common auth patterns (form login, OAuth, SSO).

Plugins

graftpunk is extensible via Python entry points or YAML configuration.

Python Plugin (Complex Logic)

# my_plugins/mybank.py
from graftpunk.plugins import SitePlugin, command

class MyBankPlugin(SitePlugin):
    site_name = "mybank"
    session_name = "mybank"

    @command(help="List all accounts")
    def accounts(self, session):
        return session.get("https://mybank.com/api/accounts").json()

    @command(help="Get statements for a month")
    def statements(self, session, month: str, year: int = 2024):
        url = f"https://mybank.com/api/statements/{year}/{month}"
        return session.get(url).json()

Register in pyproject.toml:

[project.entry-points."graftpunk.cli_plugins"]
mybank = "my_plugins.mybank:MyBankPlugin"

YAML Plugin (Simple Calls)

For straightforward GET/POST calls, no Python needed:

# ~/.config/graftpunk/plugins/mybank.yaml
site_name: mybank
session_name: mybank
help: "Commands for MyBank"

commands:
  accounts:
    help: "List all accounts"
    method: GET
    url: "https://mybank.com/api/accounts"

  statements:
    help: "Get statements for a month"
    method: GET
    url: "https://mybank.com/api/statements/{year}/{month}"
    params:
      - name: month
        required: true
        help: "Month name"
      - name: year
        default: 2024
        help: "Year"

Then use directly:

gp mybank accounts
gp mybank statements --month january --year 2024

Security

Your Data, Your Rules

graftpunk is for automating access to your own accounts. You're not scraping other people's dataโ€”you're building tools to access information that already belongs to you.

Some services may consider automation a ToS violation. Use your judgment.

Encryption

  • Algorithm: Fernet (AES-128-CBC + HMAC-SHA256)
  • Key storage: ~/.config/graftpunk/.session_key with 0600 permissions
  • Integrity: SHA-256 checksum validated before deserializing

โš ๏ธ Pickle Warning

graftpunk uses Python's pickle for serialization. Only load sessions you created.

Best Practices

  • Keep your encryption key secure
  • Don't share session files
  • Run graftpunk on trusted machines
  • Use unique, strong passwords for automated accounts

Development

git clone https://github.com/stavxyz/graftpunk.git
cd graftpunk
just setup    # Create venv and install deps
just check    # Run lint, typecheck, tests
just build    # Build for PyPI

License

MIT Licenseโ€”see LICENSE.

Acknowledgments


Built for automating your own data access.

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

graftpunk-1.1.0.tar.gz (89.7 kB view details)

Uploaded Source

Built Distribution

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

graftpunk-1.1.0-py3-none-any.whl (78.7 kB view details)

Uploaded Python 3

File details

Details for the file graftpunk-1.1.0.tar.gz.

File metadata

  • Download URL: graftpunk-1.1.0.tar.gz
  • Upload date:
  • Size: 89.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.1

File hashes

Hashes for graftpunk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1af946101052638c9f8160a494498fa388225fa3a8880fe53665753e8d621e21
MD5 d6293f56be7afa3150c6f461905caa5b
BLAKE2b-256 b39438e60d3b3328ff7f63d1479b035e2b6e976f7038cb295e89f98ae83dda92

See more details on using hashes here.

File details

Details for the file graftpunk-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: graftpunk-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 78.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.1

File hashes

Hashes for graftpunk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ba24b5d519a797c9ce506c724d8b8fdb392377e09b11753a264691e44929118
MD5 ae76e176b670410739b62d09d2788d30
BLAKE2b-256 c735741d5d7fe152892755f03308492bfe4c5e1308c544f64fb7bbb551639926

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