Project Structure

Running webcompy init inside an existing Python project scaffolds an application package with this layout:

webcompy-project/
├── app/
│   ├── __init__.py
│   ├── app.py              # the WebComPyApp instance
│   ├── router.py           # route table
│   └── components/         # your components (home.py, ...)
├── webcompy_config.py      # build + server configuration
├── pyproject.toml          # project metadata and browser dependencies
├── webcompy-lock.json      # locked browser dependency versions
├── static/                 # static files served as-is
└── dist/                   # generated output (SSG)

The app package#

app/app.py holds the WebComPyApp instance — the central object that owns routes, head metadata, styles, and scripts. app/router.py maps URL paths to lazily-loaded components, and app/components/ holds the components themselves. Each component file defines one or more @define_component() functions that render as custom elements.

Configuration: build vs server#

webcompy_config.py separates two concerns in one file:

config = WebComPyBuildConfig(
    app_module,              # your app package (imported as a module)
    dependencies=None,       # explicit browser deps (or resolve from pyproject)
    dependencies_from=None,  # e.g. "browser": read browser deps from pyproject
    server=WebComPyServerConfig(port=8080),  # dev server / SSR serving options
)
  • The WebComPyBuildConfig fields (dependencies, dependencies_from, lockfile sync) control how browser dependencies are resolved and locked for the PyScript runtime.
  • The server field (WebComPyServerConfig) controls serving only — port, and related runtime options. It never affects the browser bundle.

Each field is explained in place where it appears; the Installation guide walks through a complete example including the browser-dependency variant.

Static files and resources#

The static/ directory holds files served verbatim — stylesheets, images, and other assets your pages reference. App-package resource files (text resources transferred to the browser) go through the resource port with an allow-list, so only declared resources are exposed.

The lockfile#

webcompy-lock.json pins the exact browser dependency versions resolved from pyproject.toml. It is generated by webcompy lock and keeps every machine — and the PyScript runtime — on identical versions. The lock workflow (lock, lock --sync, lock --export, lock --install) is covered in the Installation guide.

dist/ is generated output from webcompy generate (static site generation). It is a build artifact, not source — regenerate rather than edit it.

Next steps#

With the layout in mind, head to the Quickstart to render your first component, inspect the full field reference in Project Configuration and CLI Reference, or browse the demos in the navigation bar.