Skip to main content

Make safe input handling effortless: validated prompts, composable validators, and honest security helpers.

Project description

VCoder

Make safe input handling effortless.

VCoder is a zero-dependency Python library for validated input prompts, composable validators, and honest security helpers. It does not claim to magically sanitize all input or to "prevent injection". Instead, it makes the safe path the easy path.

from vcoder import vc

name = vc.text("Name: ")
age = vc.int("Age: ", min=0, max=120)
email = vc.email("Email: ")
password = vc.password("Password: ", min_length=12)
choice = vc.choice("Language: ", ["Python", "Rust", "Go"])
numbers = vc.list("Numbers: ", parser=int)

Every prompt validates, reprompts on failure, supports defaults and optional input, accepts custom validators and custom error messages — so you never write a validation loop by hand.

Why VCoder?

  • Pythonic & discoverable. One import (vc) surfaces everything.
  • Strongly typed. Fully annotated; passes mypy --strict and pyright.
  • Zero dependencies. Standard library only.
  • Composable validators. Validator(MinLength(8), Regex(...), NoControlCharacters()).
  • Honest security helpers. For paths, filenames, shell, SQL, HTML and passwords — with documented limitations, never misleading guarantees.

Installation

pip install vcoder

From source (development):

git clone https://github.com/bitilia/vcoder
cd vcoder
pip install -e ".[dev]"

Requires Python 3.9+.

Quick tour

Input functions

from vcoder import vc

vc.text("Name: ", min_length=1)
vc.int("Age: ", min=0, max=120)
vc.float("Ratio: ", min=0.0, max=1.0)
vc.decimal("Price: ")                    # exact, for money
vc.bool("Continue? ")                    # yes/no
vc.choice("Pick: ", ["a", "b", "c"])
vc.list("CSV: ", parser=int)
vc.json("Payload: ")
vc.date("When: ")                        # ISO 8601 by default
vc.uuid("Id: ")
vc.email("Email: ")
vc.url("Site: ")                         # http/https only by default
vc.ip("Addr: ")
vc.port("Port: ")
vc.password("Password: ", min_length=12) # never echoed, never logged
vc.filename("File: ")                    # rejects reserved/illegal names
vc.path("Path: ", within="/srv/uploads") # blocks traversal

All 26 input types accept the same keyword contract: default, optional, retries, error_message, validators, reader.

The reader= keyword lets you inject input (used throughout the tests and in the doctests). In real use you omit it and VCoder reads from the terminal.

Composable validators

from vcoder import Validator, MinLength, Regex, NoControlCharacters, ValidationError

username = Validator(
    MinLength(3),
    Regex(r"[a-z0-9_]+"),
    NoControlCharacters(),
)
username.validate("ada_lovelace")   # ok
username.is_valid("x")              # False

# Extending is just subclassing:
class EvenNumber(Validator):
    def validate(self, value):
        if value % 2:
            raise ValidationError("must be even", value=value)

Use any validator with any prompt via validators=[...].

Security helpers

from vcoder import vc

# Paths — anchored to a root, traversal-aware (raw, %2e-encoded, unicode).
vc.safe_join("/srv/uploads", user_supplied)      # -> Path or UnsafePathError
vc.contains_traversal("../../etc/passwd")        # True

# Subprocess — argument lists only, never a shell.
vc.run(["git", "status"])
vc.run_capture(["echo", user_supplied])          # metacharacters are inert

# SQL — parameterized by construction.
query, params = vc.sql.build_select("users", where={"id": 1})
vc.sql.execute(cursor, query, params)

# HTML — context-aware escaping.
vc.html.escape(user_supplied)                    # for text nodes
vc.html.escape_attribute(user_supplied)          # for quoted attributes

# Passwords — configurable strength, optional HIBP check.
vc.validate_password(pw)                          # PasswordTooWeak on failure

Global configuration

from vcoder import vc

vc.configure(retries=5, strip=True, lowercase=False, logging=True)

What VCoder protects against (and what it does not)

See SECURITY.md for the full, honest breakdown. In short:

  • It reduces the risk of path traversal, shell injection, accidental SQL string-building, XSS from untrusted text, and weak passwords.
  • It cannot guarantee the absence of any of these. Validation is context-dependent, symlinks and TOCTOU races exist, and the program you invoke may still mishandle its arguments. Use least privilege and defense in depth.

Documentation

Development

pip install -e ".[dev]"
pytest                 # tests + doctests, 95%+ coverage
mypy                   # strict type checking
ruff check .           # linting
black --check .        # formatting

License

MIT © 2026 VCoder contributors.

Project details


Download files

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

Source Distribution

vcoder-0.2.0.tar.gz (60.8 kB view details)

Uploaded Source

Built Distribution

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

vcoder-0.2.0-py3-none-any.whl (45.4 kB view details)

Uploaded Python 3

File details

Details for the file vcoder-0.2.0.tar.gz.

File metadata

  • Download URL: vcoder-0.2.0.tar.gz
  • Upload date:
  • Size: 60.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vcoder-0.2.0.tar.gz
Algorithm Hash digest
SHA256 04caf0599b56ac9adc07e118f16b36866c0c9af7c97555160bf1f99091b5a8cb
MD5 859f092aca2cb5baec1631d1aa21ef9d
BLAKE2b-256 19e2476bc04e40be5a21fa928f509bb1b47779a1fb207f2bbfda90eeaeeaab3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcoder-0.2.0.tar.gz:

Publisher: publish.yml on bitilia/vcoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vcoder-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: vcoder-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vcoder-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ff662f604f96f7651a2ad766d9cb76f02c81b64f55bb9657697346cc7e91707
MD5 f05aee79207a0d5e610a2a452c39e15e
BLAKE2b-256 f256dccd46c12942a6fbec8469baa44539a58545368e50646ecbbeedd15da70a

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcoder-0.2.0-py3-none-any.whl:

Publisher: publish.yml on bitilia/vcoder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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