Skip to main content

Python-dsl code converter to html parser for web scraping

Project description

ssc-codegen

Code generator for web scraping parsers. Describe HTML extraction rules in a declarative KDL 2.0 DSL, then generate ready-to-use parser code for multiple languages and libraries.

.kdl schema --> [kdl parser] --> AST --> [linter] --> [converter] --> output code

Features

  • Declarative DSL based on KDL 2.0 syntax
  • Static type checking and linting before code generation
  • Multiple output targets: Python (bs4, lxml, parsel, selectolax), JavaScript (DOM API)
  • Struct types: item, list, dict, table, flat
  • LLM-friendly: system prompt + linter loop for AI-assisted schema generation

Install

uv tool install ssc_codegen

Quick example

books.kdl:

(list)struct Book {
    @split-doc { css-all ".product-card" }

    title { css ".title"; text }
    price { css ".price"; text; re #"(\d+\.\d+)"#; to-float }
    url   { css "a[href]"; attr "href"; fallback #null }
}

Generate Python parser:

ssc-gen generate books.kdl -t py-bs4 -o ./output

Usage

Generate code

# single file
ssc-gen generate schema.kdl -t py-bs4 -o ./output

# all .kdl files in a directory
ssc-gen generate examples/ -t js-pure -o ./output

# with custom package name
ssc-gen generate schema.kdl -t py-bs4 -o ./parsers --package scraper

Targets: py-bs4, py-lxml, py-parsel, py-slax, js-pure

Lint schemas

# human-readable output
ssc-gen check schema.kdl

# JSON output (for LLM pipelines)
ssc-gen check schema.kdl -f json

# check all files in a directory
ssc-gen check examples/

Test schema against HTML

# from file
ssc-gen run examples/booksToScrape.kdl:MainCatalogue -t py-bs4 -i page.html

# from stdin
curl https://books.toscrape.com/ | ssc-gen run examples/booksToScrape.kdl:MainCatalogue -t py-bs4

Health check (verify selectors match elements)

# from file
ssc-gen health examples/booksToScrape.kdl:MainCatalogue -i page.html

# from stdin
curl https://books.toscrape.com/ | ssc-gen health examples/booksToScrape.kdl:MainCatalogue

Documentation

LLM integration

LLM agents can generate and validate .kdl schemas automatically using the linter feedback loop.

In chats (ChatGPT, Claude, etc.)

Use SYSTEM_PROMPT.md as system prompt. After generation, run ssc-gen check -f json and send errors back to the LLM for correction.

In AI-powered IDEs (Claude Code, Cursor, etc.)

Use the kdl-schema-dsl skill for automatic generation, validation, and iteration.

Development

uv sync                  # install dependencies
uv build --wheel         # build wheel
uv run pytest            # run tests
uv run ruff check ssc_codegen/

Test dependencies

Python tests require only uv sync. JS integration tests additionally need:

npm install      # installs jsdom (dev dependency in package.json)

Node.js must be installed and available as node in PATH. JS tests are automatically skipped if Node.js is not found.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssc_codegen-0.29.0.tar.gz (105.7 kB view details)

Uploaded Source

Built Distribution

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

ssc_codegen-0.29.0-py3-none-any.whl (129.4 kB view details)

Uploaded Python 3

File details

Details for the file ssc_codegen-0.29.0.tar.gz.

File metadata

  • Download URL: ssc_codegen-0.29.0.tar.gz
  • Upload date:
  • Size: 105.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ssc_codegen-0.29.0.tar.gz
Algorithm Hash digest
SHA256 c0c50f5aee8c434118970531b58308f7865f848a398e6688b2b75830ee9deb2e
MD5 eed060be7050bb2e334b62e0a62c6757
BLAKE2b-256 13e7410b2c6af9c29fe6040f1f0911f90b5cfbe2d7eaad499f2ad83e3bef66e1

See more details on using hashes here.

File details

Details for the file ssc_codegen-0.29.0-py3-none-any.whl.

File metadata

  • Download URL: ssc_codegen-0.29.0-py3-none-any.whl
  • Upload date:
  • Size: 129.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ssc_codegen-0.29.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83e89965e55de558c8a9f123d2258866eaf3c1d8d9e83b545dd45797c335fcf1
MD5 fa66fb63a9e81714a0243f687d91dc58
BLAKE2b-256 0b2066dc9b2562e5a4a40de0f45e3caea8ed452b4ccfedf92cc3439f77615515

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