| layout | default |
|---|---|
| title | API reference |
| nav_order | 5 |
This reference lists the complete public surface of VCoder. Every function is
fully type-hinted and carries a docstring with examples; use help(vc.int) (etc.)
for the authoritative, always-current details.
from vcoder import vcvc is a single stateless object that exposes every input function, the security
helpers, and the vc.sql / vc.html sub-namespaces. Everything is also
importable from its own module (e.g. from vcoder.validators import MinLength).
All input functions share these keyword parameters:
default— value for empty input (omit for required)optional: bool = False— empty input returnsNonewhen nodefaultretries: int | None = None— attempts beforeRetryLimitExceedederror_message: str | None = None— custom failure messagevalidators: Iterable = ()— extra validators/callablesreader: Callable[[str], str] | None = None— injectable input sourcerate_limit: RateLimiter | None = None— cap how fast the input may be submitted; each attempt raisesRateLimitExceededonce the limit is hit
| Function | Returns | Type-specific parameters |
|---|---|---|
vc.text(prompt) |
str |
min_length, max_length, pattern |
vc.int(prompt) |
int |
min, max, base |
vc.float(prompt) |
float |
min, max (rejects nan/inf) |
vc.decimal(prompt) |
Decimal |
min, max |
vc.bool(prompt) |
bool |
— (accepts y/yes/true/1/on, n/no/false/0/off) |
vc.choice(prompt, choices) |
matched item | case_insensitive |
vc.list(prompt) |
list |
parser, separator, min_items, max_items, skip_empty |
vc.tuple(prompt) |
tuple |
parser, separator, length |
vc.dict(prompt) |
dict |
key_parser, value_parser, item_separator, kv_separator |
vc.json(prompt) |
parsed JSON | — |
vc.date(prompt) |
datetime.date |
formats, min, max |
vc.time(prompt) |
datetime.time |
formats |
vc.datetime(prompt) |
datetime.datetime |
formats, min, max |
vc.uuid(prompt) |
uuid.UUID |
version |
vc.email(prompt) |
str |
lowercase |
vc.url(prompt) |
str |
schemes, require_host |
vc.ip(prompt) |
IPv4Address/IPv6Address |
version |
vc.mac(prompt) |
str |
— |
vc.hostname(prompt) |
str |
— (RFC 1123) |
vc.port(prompt) |
int |
allow_zero |
vc.password(prompt) |
str |
min_length, policy, confirm, confirm_prompt |
vc.filename(prompt) |
str |
allow_unicode, max_length |
vc.directory(prompt) |
Path |
must_exist, within |
vc.path(prompt) |
Path |
must_exist, within |
vc.regex(prompt) |
re.Pattern |
flags |
vc.enum(prompt, enum_class) |
enum member | by ("name"/"value"), case_insensitive |
Notes:
vc.passwordreads without echoing, never logs the value, and never strips or lowercases it. It is notoptional; the policy rejects empty input.vc.path/vc.directorywithwithin=block traversal by reprompting.
Example signatures (see docstrings for the rest):
def int(prompt="", *, min=None, max=None, base=10,
default=UNSET, optional=False, retries=None,
error_message=None, validators=(), reader=None) -> int | None: ...
def password(prompt="Password: ", *, min_length=12, policy=None,
confirm=False, confirm_prompt="Confirm password: ",
retries=None, error_message=None, validators=(),
reader=None) -> str: ...vcoder.core.run_prompt(prompt, converter, validators=(), *, default=UNSET, optional=False, retries=None, error_message=None, reader=None, secret=False, sanitizer=None, stream=None) is the public engine behind every input function.
Build your own prompt types with identical behavior by supplying a converter.
Import from vcoder or vcoder.validators.
Validator(*children)— base class & composite; methodsvalidate(value),is_valid(value) -> bool, and__call__.Predicate(func, message="invalid value")Min(minimum),Max(maximum),Range(minimum=None, maximum=None)MinLength(n),MaxLength(n),Length(min=None, max=None, *, exact=None)Regex(pattern, flags=0, *, full=True)NoControlCharacters(),Printable(),Ascii(),NoWhitespace()Unicode(allow=None, deny=None)Entropy(min_bits, *, estimator=estimate_password_bits)Unique()Blacklist(forbidden, *, case_insensitive=False)Whitelist(allowed, *, case_insensitive=False)(aliasOneOf)
from vcoder import Config, configure, get_config, reset_config, config_scopeConfig(retries=3, strip=True, lowercase=False, logging=False, prompt_suffix="")— immutable dataclass.configure(**changes) -> Config— update global config (unknown keys raise).get_config() -> Configreset_config() -> Configconfig_scope(**changes)— context manager restoring previous config on exit.
vc.configure, vc.get_config, vc.reset_config, vc.config_scope mirror these.
from vcoder import (
VCoderError, ValidationError, RetryLimitExceeded, RateLimitExceeded,
SecurityError, UnsafePathError, UnsafeSQLQuery, UnsafeShellArgument,
PasswordTooWeak, ConfigurationError,
)VCoderError
├── ConfigurationError
├── ValidationError
│ └── PasswordTooWeak
├── RetryLimitExceeded
├── RateLimitExceeded
└── SecurityError
├── UnsafePathError
├── UnsafeSQLQuery
└── UnsafeShellArgument
ValidationError(message, *, value=None) stores the offending value but never
includes it in str(). RetryLimitExceeded carries attempts and last_error.
RateLimitExceeded carries retry_after (seconds).
from vcoder import RateLimiter # also vc.RateLimiterRateLimiter(max_calls, per, *, clock=time.monotonic)— sliding-window, thread-safe.check(key=None) -> None— record a call or raiseRateLimitExceeded.allow(key=None) -> bool— non-raising; a rejected call is not recorded.remaining(key=None) -> int,reset(key=None),reset_all().
Pass a key (client IP, user id, ...) for independent per-caller budgets, or
attach a limiter to any prompt via rate_limit=.
contains_traversal(value) -> boolsafe_join(root, *parts) -> Pathresolve_within(root, candidate) -> Pathis_within(root, candidate) -> bool
validate_filename(name, *, max_length=255, allow_unicode=True) -> strsanitize_filename(name, *, replacement="_", max_length=255, fallback="file") -> stris_reserved_name(name) -> bool- Constants:
MAX_FILENAME_LENGTH,WINDOWS_RESERVED_NAMES,ILLEGAL_FILENAME_CHARS
run(args, *, allowed_dirs=None, timeout=None, **kwargs) -> CompletedProcess[str]run_checked(args, ...) -> CompletedProcess[str](check=True)run_capture(args, *, check=True, ...) -> strsanitize_args(args) -> list[str]resolve_executable(name, *, allowed_dirs=None) -> str
shell and executable kwargs are rejected for safety.
valid_identifier(name) -> boolguard_query(query, params=None) -> Noneexecute(cursor, query, params=None)build_select(table, columns=None, where=None, *, style="qmark") -> (query, params)build_insert(table, values, *, style="qmark") -> (query, params)select(cursor, table, columns=None, where=None, *, style="qmark")insert(cursor, table, values, *, style="qmark")
style is "qmark" (?), "format" (%s), or "named" (:name).
escape(value, quote=True) -> strescape_attribute(value) -> strstrip_html(value) -> strsafe_html(value) -> str
from vcoder import PasswordPolicy
from vcoder.passwords import (
is_common_password, password_strength, check_hibp, validate_password,
COMMON_PASSWORDS,
)PasswordPolicy(min_length=12, max_length=4096, min_bits=0.0, require_lower=False, require_upper=False, require_digit=False, require_symbol=False, forbid_common=True, check_pwned=False, pwned_fail_open=False, extra_forbidden=frozenset())—.check(password)raisesPasswordTooWeak.validate_password(password, policy=None) -> strpassword_strength(password) -> float(bits)is_common_password(password) -> boolcheck_hibp(password, *, timeout=5.0) -> int— network call, k-anonymity.
vc.validate_password, vc.password_strength, vc.check_hibp,
vc.is_common_password mirror these.
shannon_entropy(value) -> floatestimate_password_bits(value) -> floatcount_pools(value) -> intnormalize_unicode(value, form="NFC") -> strhas_control_characters(value) -> boolis_printable(value) -> boolall_unique(items) -> bool
strip,collapse_whitespace,to_lowercase,to_uppercase,normalize,remove_control_characters,compose(*sanitizers),default_input_sanitizer.