Skip to main content

nyxa-forms

Web validation for the Nyxa framework — injectable FormRequest classes, ~115 pipe-separated string rules, custom rules via @rule, error bags + old input flashing, and redirect-back semantics for HTML forms.

Features

  • FormRequest — self-validating request classes injected by type into handlers: rules(), authorize(ctx), messages(), attributes(), prepare_for_validation(), with_validator(), after(), validated(*keys), errors(), input(key).
  • Validator — Validator(data, rules, app=, ctx=); await v.validate(), v.validated(), plus validate_sync for non-async paths. Dot-key paths reach into nested payloads.
  • ~115 built-in rules — presence (required, filled, present, missing, prohibited and their *_if/*_unless/ *_with/*_without variants), exclusion (exclude*), comparison (same, different, gt/gte/lt/lte, between, in/not_in/in_array/any_of, multiple_of), strings (alpha*, ascii, starts_with/ends_with/contains(+doesnt_*), regex/not_regex, lowercase/uppercase, hex_color), types (string, boolean, integer, numeric, decimal, list, array, json, file, image, mimes/mimetypes, extensions, dimensions), numerics (min/max/size, digits*), dates (date, before/after(+_or_equal), date_equals, date_format, timezone), network (url, active_url, ip/ipv4/ipv6, mac_address), identifiers (uuid, ulid, email, name, encoding), database (exists, unique, current_password), and confirmed/nullable/ distinct/prohibits/enum.
  • Rule objects — Password(min=8, letters=…, mixed_case=…, numbers=…, symbols=…) (alias PasswordRule) and Enum(MyEnum) mix into rule specs alongside strings.
  • @rule — register custom rules: @rule / @rule("name") / @rule(implicit=True, exclude=True, needs_field=True); custom rules can shadow built-in names.
  • HTML form semantics — FormsExceptionHandler wraps the app's handler: a ValidationException on a non-JSON request redirects back (303) with errors + old input flashed; JSON requests get 422.
  • ctx macros — ctx.validate_web(rules), ctx.old(key), ctx.errors([key]), ctx.back(fallback="/").
  • Helpers — old(ctx, key), errors(ctx[, key]), with_errors(ctx, bag), flash_old(ctx, data), back(ctx, fallback="/") from nyxa_forms.helpers.
  • make:request — nyxa make:request StorePostRequest scaffolds a FormRequest (--fields name:type[:rules], --update, --describe, --force).

Install

nyxa add nyxa-forms   # writes config/forms.py

Usage

from nyxa_forms import FormRequest, Password


class StorePost(FormRequest):
    def rules(self):
        return {"title": "required|string|max:255", "password": ["required", Password(min=12, numbers=True)]}

    def authorize(self, ctx):
        return ctx.user is not None


async def store(ctx, request: StorePost):
    data = request.validated()  # only keys that passed rules

Inline validation + manual error handling:

async def handler(ctx):
    data = await ctx.validate_web({"email": "required|email"})

Custom rule:

from nyxa_forms import rule


@rule
def strong(value, params, data, validator):
    return isinstance(value, str) and len(value) >= 12 or "Too weak."

Public API

  • FormRequest — injectable base (see Usage). Handler params typed to a subclass are decoded, authorized, and validated by the FormRequestKind contract.
  • Validator — Validator(data, rules, app=None, ctx=None); await v.validate() -> dict, v.validated() -> dict, v.errors, v.messages/v.attributes overrides.
  • ValidationException — raised on failure (HTTP 422): exc.bag ({field: [messages]}), exc.data (submitted payload).
  • rule — decorator registering a rule function (value, params, data, validator) -> bool | str; keyword flags implicit, exclude, needs_field.
  • Password — password-policy rule object: Password(min=8, letters=False, mixed_case=False, numbers=False, symbols=False); Password.defaults().
  • PasswordRule — alias of Password.
  • Enum — enum rule object: Enum(MyEnum) accepts member instances, backing values, and names.
  • FormsProvider — registers the FormRequest contract kind, wraps the exception handler, adds the ctx macros, contributes make:request, and writes config/forms.py on nyxa add.

Configuration

nyxa add nyxa-forms writes config/forms.py (FORMS = {} — reserved for validation behavior overrides).

Testing

v = Validator({"email": "nope"}, {"email": "required|email"})
try:
    await v.validate()
except ValidationException as e:
    assert "email" in e.bag

License

MIT

Metadata

Release files for nyxa-forms 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nyxa-forms 0.0.1
File Size Uploaded Provenance Actions
nyxa_forms-0.0.1.tar.gz 37.6 kB Without provenance Details for nyxa_forms-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nyxa-forms 0.0.1
File Interpreter ABI Platform Actions
nyxa_forms-0.0.1-py3-none-any.whl Python 3 none any Details for nyxa_forms-0.0.1-py3-none-any.whl

Total release size: 68.5 kB

Release files / nyxa_forms-0.0.1.tar.gz

Download URL nyxa_forms-0.0.1.tar.gz
Size 37.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8ce47865b42aed75bb4a720d096f4c128b19f4880dc1a4304b268ec14a969f11
BLAKE2b-256 checksum
How to use checksums
fd85671308dddb9fa3dca0c4a13501d6c0cb71316b4f0d439bbeae8563204dcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nyxa_forms-0.0.1-py3-none-any.whl

Download URL nyxa_forms-0.0.1-py3-none-any.whl
Size 30.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1b113a80758762366b4b284281ec57e1be4f455d0a3dd54e575017f7f832bb5
BLAKE2b-256 checksum
How to use checksums
73d2a388725a78bbd56e71e456ec3e7b3945450d4b34e1367c7c4747049564ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for nyxa-forms 0.0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page