codecraftai-webworks
Code Craft AI - WebWorks
Overview
codecraftai-webworks is the web framework of the Code Craft AI technology stack. It is a Python package (ccai.webworks) for building web applications and REST APIs, and it ships the browser-side pieces that go with them: a library of mj-* web components, a chart library and an API explorer, all served as static assets with no build step.
An application is built around a web application persona: one object that owns the application’s identity, its configuration, its endpoint registry, its router and its ASGI application. Endpoints are plain functions or classes marked with a decorator; the application declares which ones belong to it and the framework builds the router from them.
What is in the package
Server side (ccai.webworks):
ASGI and WSGI layers (asgi, wsgi): an ASGI 3.0 application with HTTP, WebSocket, server-sent event and lifespan handling, and a WSGI layer with request parsing, response building, a socket server and the bridge that serves a WebApplication over WSGI.
Routing (routing): a URL-node router with path parameters and converters, a dispatcher, request and response classes (JSON, HTML, redirect, streaming), multipart parsing and a middleware pipeline.
Endpoints and blueprints (endpoints): Endpoint.attach_at for single handlers; Blueprint and RestBlueprint for groups of handlers under a base path; access policies and rate limits declared on the endpoint.
REST and OpenAPI (endpoints.rest, openapi): request and response schemas, content negotiation, an OpenAPI generator, Swagger UI, ReDoc and the bundled API explorer. A route that declares a request schema, response schema or error map is REST-processed automatically (validation, negotiation, serialization, REST error bodies); pass rest_processing=False when registering it to handle the raw request yourself.
Authentication and security (authentication, security): basic, bearer, digest, HMAC, API key, session, OAuth 2 and OpenID Connect authenticators; access policies, CSRF protection, signed serialization, JSON web tokens and password hashing.
Templating (templating): a pluggable template engine interface with Jinja2 and Mako adapters, context processors, filters and auto-escaping.
Configuration (configuration): layered configuration from files, the environment and defaults, with schema validation.
Extensions (extensibility): add extensions in code with webapp.add_extension(...) or list them in the extensions configuration section (load, entry_points, paths, with an allowed_packages allow-list); they get application and request lifecycle hooks and can contribute middleware. Nothing is imported unless it is configured.
Markdown books (markdown, books): a CommonMark renderer with no third-party dependency, and a blueprint that serves a folder of markdown books as navigable HTML (see Markdown Books).
Developer tools (devexp): the webworks command line, a development server with auto-reload, an in-process test client, debug error pages and request inspection (see The webworks command line).
Production server (prodserver): webworks prodserve runs an application on pre-forked worker processes with graceful shutdown and reload, request IDs, health and metrics endpoints, a structured access log, request limits and TLS. A WebApplication is also served by any WSGI server through webapp.wsgi_app.
Browser side (ccai/webworks/static, shipped inside the package):
The mj-* component library: native custom elements (see The mj-* component library).
The chart library: <mj-chart> and its renderers (see The chart library).
Installation
The package requires Python 3.10 or later. Releases are built by the Publish workflow and uploaded to the Code Craft AI package repository (and to PyPI when the organization enables it). With that repository configured as a package source:
pip install codecraftai-webworks
Optional features are installed as extras:
Extra |
Installs |
|---|---|
jinja2 |
Jinja2, for the Jinja2 template adapter |
mako |
Mako, for the Mako template adapter |
templating |
both template engines |
pydantic |
Pydantic 2, for Pydantic models as REST schemas and in the OpenAPI schema converter |
gevent |
gevent, for the gevent worker of the production server |
toml |
tomli (Python 3.10) and tomli-w, for TOML configuration files |
shell |
IPython, used by webworks shell when it is installed |
test |
the testbase runner and Playwright, for running the test suites |
pip install "codecraftai-webworks[jinja2,pydantic]"
A minimal application
Save this as app.py:
from ccai.webworks.endpoints.endpoint import Endpoint
from ccai.webworks.routing.request import Request
from ccai.webworks.routing.response import JSONResponse
from ccai.webworks.webapplication import establish_webapp_persona
@Endpoint.attach_at(path="/", methods=["GET"])
def index(request: Request) -> JSONResponse:
return JSONResponse(content={"message": "Hello, World!"}, status_code=200)
webapp = establish_webapp_persona(
name="hello",
logger_name="hello",
log_basename="hello",
presence_dir=".presence",
)
# The decorator only marks the handler; collecting it registers the route.
webapp.registry.collect_from(index)
webapp.startup()
# The ASGI application: serve it with 'webworks serve' or any ASGI server.
app = webapp.asgi_app
Serve it from the same directory and request it:
webworks serve --reload
curl http://127.0.0.1:8000/
webworks serve looks for app:app in the current directory; name another application with --app module:attribute. With --reload the server runs in a child process that is replaced whenever a source file changes, so the edited code is imported afresh.
The same application can be called in a test without a server:
from ccai.webworks.devexp.testing.testclient import TestClient
from app import app
client = TestClient(app)
response = client.get("/")
assert response.status_code == 200
assert response.json == {"message": "Hello, World!"}
The webworks command line
Installing the package adds the webworks command. It can also be run as python -m ccai.webworks.devexp.cli.
Command |
Does |
|---|---|
webworks new NAME |
Create a project. --template minimal (default), api or webapp. |
webworks serve |
Run the development server. --app, --host, --port, --reload, --debug, --no-debug, --extra-files, --log-level, --log-file. |
webworks routes |
List the application’s routes. --format table|json|csv, --filter, --verbose. |
webworks shell |
Open a Python shell with app, webapp, router and registry loaded. |
webworks generate endpoint NAME |
Write an endpoint module. --output-dir, --dry-run. |
webworks generate blueprint NAME |
Write a RestBlueprint module. --output-dir, --dry-run. |
webworks db init |
Run the persona’s database hooks. migrate, rollback, seed and status need a database backend provided by the application. |
The global options --app, --config FILE (a JSON file), --env and --verbose go before the command name. Settings can also come from the environment: WEBWORKS_SERVER_PORT=9000 sets server.port. The user guide’s Getting Started chapter walks through all of this.
The development server is for development. In debug mode an unhandled error is answered with its traceback, so debug mode is switched off when the server binds to an address other machines can reach, unless --debug is given explicitly.
The mj-* component library
ccai/webworks/static holds a framework-agnostic library of native custom elements in eleven groups: buttons, selection, text, data, navigation, overlays, layout, feedback, media, productivity and charts. Each component is one ES module under static/javascript/components (mj<name>.js) built on a small shared foundation in static/javascript/core. There is no build step and no runtime dependency.
<!-- Design tokens: link once at the document level. -->
<link rel="stylesheet" href="/static/styles/tokens.css">
<!-- All components, registered automatically. -->
<script type="module" src="/static/javascript/index.js"></script>
<mj-button variant="primary">Save</mj-button>
Components are styled only through --mj-* design tokens (static/styles/tokens.css), with light, dark and high-contrast themes selected by a data-theme attribute on any ancestor. An application serves the directory itself; the testcomponents site shows how in source/testsites/testcomponents/endpoints/handlers.py. The library’s own documentation is source/packages/ccai/webworks/static/javascript/README.md and a live demo of components, docking, anchoring and theming is static/gallery.html.
The chart library
static/javascript/charts is a chart library built on the same foundation. A chart is an <mj-chart> element whose type selects a renderer (bar, line, pie, scatter, heatmap, sankey and many more; each renderer is a module under charts/core/renderers) and whose data is JSON given through the data property, a src URL or an inline <script type="application/json">. The title, legend and data table of a chart are separate elements (<mj-chart-title>, <mj-chart-legend>, <mj-chart-data-table>) that bind to the chart by its id and can be placed independently.
<script type="module" src="/static/javascript/charts/index.js"></script>
<mj-chart id="sales" type="bar" src="/api/sales.json"></mj-chart>
<mj-chart-legend chart="sales"></mj-chart-legend>
The exact attributes and the data shape of every chart type are documented, with live examples, by the testcomponents site.
The test sites
source/testsites holds three sample applications. They are fixtures for the test suites and working examples of the framework:
helloworld: the smallest application; two endpoints.
blueprintdemo: RestBlueprint inheritance with OpenAPI and Swagger UI at /docs.
testcomponents: documents and exercises the component and chart libraries. It has a browse-by-group landing page, a page per component with attribute and event tables and a live, editable playground, and a /charts section with a page per chart type. It needs no authentication.
Run one from the repository root:
PYTHONPATH=source/testsites webworks serve --app testcomponents.app:app
Markdown Books
BooksBlueprint serves a folder of markdown books as HTML pages. Navigation comes from the links in the markdown, not from the folders the files are in: the library’s index document (README.md at the root) links to the books, each book’s index document links to its chapters, and the order of those links, in lists or tables, is the reading order. The text of each link is the title the navigation shows. A link to a folder means the folder’s README.md (or index.md).
from ccai.webworks.books import BookLibrary, BooksBlueprint
library = BookLibrary("~/repos/codecraftai-books")
books = BooksBlueprint(library, mount_path="/books")
books.attach_to_webapp(webapp)
Each page shows its book’s contents, breadcrumbs, links to the previous and next documents and an outline of its headings. Links between the markdown files are rewritten to the URLs the documents are served at, and images in the library are served beside them. Nothing outside the library’s folder, and no hidden file, is ever served. Pages carry a Content-Security-Policy that allows no script.
The markdown is rendered by ccai.webworks.markdown (no third-party library): CommonMark plus GitHub tables, strikethrough and links made from bare addresses. Raw HTML in the markdown is escaped and links with unsafe schemes such as javascript: are dropped.
To read a library with the development server:
python source/examples/books/serve_books.py ~/repos/codecraftai-books --port 8000
Development
The repository uses Poetry for its environment.
Prepare the checkout and create the virtual environment in .venv:
python repository-setup/rehome-repository python development/setup-environment poetry install --extras "templating test" source .venv/bin/activateRun the single-host suite. Tests run under the testbase runner:
testbase testing run --root source/testroots/ccai --includes=ccai.tests.singlehost --output=./.output/Run the browser suite of the testcomponents site. It drives the component and chart libraries in Chromium through Playwright (installed by the test extra); download the browser once first. Without Playwright or its browser every test in this suite is reported as skipped, not passed:
python -m playwright install chromium testbase testing run --root ./source/testsites/testcomponents --includes=testcomponents.tests --output=./.output/testcomponents-tests
The Merge Gate workflow runs both suites, builds the wheel and smoke-tests it; the Publish workflow uploads a release only after that gate has passed. make test, make test-components and make dist-build run the same steps locally.
References
Metadata
Release files for codecraftai-webworks 1.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| codecraftai_webworks-1.7.0.tar.gz | 3.0 MB | With provenance | Details for codecraftai_webworks-1.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| codecraftai_webworks-1.7.0-py3-none-any.whl | Python 3 | none | any | Details for codecraftai_webworks-1.7.0-py3-none-any.whl |
Total release size: 6.3 MB
Release files / codecraftai_webworks-1.7.0.tar.gz
| Download URL | codecraftai_webworks-1.7.0.tar.gz |
|---|---|
| Size | 3.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14fd3fbedd95406788ccd3c63dc3fb78fdbb76520f8a104b7105592d2df26288
|
|
BLAKE2b-256 checksum How to use checksums |
c42fe0c535d9e645ab0082dfb4b8223d6295d944e8a39db9e7386b904fea8d34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / codecraftai_webworks-1.7.0-py3-none-any.whl
| Download URL | codecraftai_webworks-1.7.0-py3-none-any.whl |
|---|---|
| Size | 3.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a94aa418d61a1424dc79c945fcea47ca410e4aefb5f4891ca1da92cd0be0d1f
|
|
BLAKE2b-256 checksum How to use checksums |
1ba32ef1336dc93992990b5e53fa4207ab0e239ca910c9ef8a7f69a6a6f3cbce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logSecurity for codecraftai-webworks 1.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for codecraftai_webworks-1.7.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.