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:

struct Book type=list {
    @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 (for Go and other targets)
ssc-gen generate schema.kdl -t go-goquery -o ./parsers --package scraper

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

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/

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.21.1.tar.gz (152.6 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.21.1-py3-none-any.whl (181.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ssc_codegen-0.21.1.tar.gz
  • Upload date:
  • Size: 152.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for ssc_codegen-0.21.1.tar.gz
Algorithm Hash digest
SHA256 b27135cd04b58e4dba8657b35989d7f923c5cebe94435ed157717d1865df694c
MD5 3eb1e1cee015740aff94a6088a41db0e
BLAKE2b-256 9650f38800c34f5f1676c2f973423e1c56a9ff7bd7a24230e8261a31516c5f3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssc_codegen-0.21.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b96c6d1c3403d0adafc4706dc6611b1c6c77b42e83850fd38972ab28d2a8216
MD5 749185f4046cc0a6c88483840fec76db
BLAKE2b-256 285f200c007674b9ac492f552a01a2f129414fa82c107b00c6826d636d0f8993

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