Skip to main content

Crate use_python

Crate use_python 

Source
Expand description

§use-python

Facade crate for the focused RustUse Python ecosystem primitives.

§Experimental

use-python is experimental while the workspace remains below 0.3.0. Expect small API adjustments during the first release wave.

§Example

use use_python::{
    PipRequirement, PythonIdentifier, PythonImplementation, PythonPrimitiveValue, PythonVersion,
    PytestNodeId,
};

let version: PythonVersion = "Python 3.12.1".parse()?;
let identifier = PythonIdentifier::new("async_task")?;
let requirement = PipRequirement::new("requests>=2")?;
let node_id = PytestNodeId::new("tests/test_app.py::test_smoke")?;

assert!(version.is_python3());
assert_eq!(identifier.as_str(), "async_task");
assert_eq!(PythonImplementation::CPython.as_str(), "cpython");
assert_eq!(PythonPrimitiveValue::None.type_name(), "NoneType");
assert!(!requirement.is_editable());
assert!(node_id.has_scope_separator());

§Scope

  • Thin re-exports over the focused crates in this workspace.
  • One dependency when consumer ergonomics matter more than the narrowest possible dependency graph.
  • Primitive metadata and validation helpers for Python ecosystem concepts.

§Non-goals

  • Python runtime behavior or object semantics.
  • Full source, TOML, requirement, lockfile, or test-file parsing.
  • Shelling out to Python ecosystem tools.
  • Package resolution, installation, virtual environment creation, linting, formatting, testing, or project generation.

§License

Licensed under either Apache-2.0 or MIT.

Structs§

PipEditableInstall
pip editable install metadata.
PipIndexUrl
pip package index URL metadata.
PipInstallTarget
PipPackageSpec
PipRequirement
Validated pip requirement text.
PipRequirementFile
pip requirements-file metadata.
PyProject
Partial pyproject.toml metadata.
PyProjectBuildSystem
Partial [build-system] metadata.
PyProjectDependency
PyProjectEntryPoint
PyProjectOptionalDependencyGroup
PyProjectProjectMetadata
Partial [project] metadata.
PyProjectScript
PyProjectToolSection
PytestFixtureName
PytestMarkerName
PytestNodeId
pytest node ID metadata.
PytestTestName
PythonAbiTag
PythonBytesValue
Python bytes value metadata.
PythonCompatibilityTag
PythonDunderName
Validated Python dunder name metadata.
PythonEllipsis
Python ellipsis metadata marker.
PythonIdentifier
Validated ASCII-safe Python identifier.
PythonImportName
PythonMajorVersion
Python major version component.
PythonMinorVersion
Python minor version component.
PythonModuleName
PythonModulePath
Python module path metadata.
PythonNone
Python None metadata marker.
PythonPackageName
PythonPatchVersion
Python patch version component.
PythonPlatformTag
PythonPrivateName
Validated Python private-name metadata.
PythonVersion
Lightweight Python version metadata.
PythonVirtualEnv
Python virtual environment metadata.
PythonVirtualEnvName
Validated virtual environment name metadata.
PythonVirtualEnvPath
Virtual environment path metadata.
UvPackageSpec
UvWorkspace

Enums§

PipCommand
Common pip command labels.
PipTextError
Error returned when pip metadata text is invalid.
PyProjectBuildBackend
Common Python build backends.
PyProjectConfigFile
Common pyproject config file labels.
PyProjectTextError
Error returned when pyproject metadata text is invalid.
PytestConfigFile
Common pytest config file labels.
PytestFileKind
pytest file-kind labels.
PytestNameError
Error returned when pytest metadata names are invalid.
PytestOutcome
pytest outcome labels.
PytestScope
pytest fixture scope labels.
PythonActivationShell
Activation shell labels.
PythonEnvVar
Python environment variable labels.
PythonFileKind
Python file-kind metadata.
PythonIdentifierError
Error returned when an ASCII Python identifier is invalid.
PythonImplementation
Python implementation label.
PythonImportKind
Python import statement kind metadata.
PythonKeyword
Common hard Python keywords.
PythonKeywordParseError
Error returned when a Python keyword label is empty or unknown.
PythonModuleNameError
Error returned when Python module name metadata is invalid.
PythonNumberValue
Primitive Python number value metadata.
PythonPackageLayout
Python package layout metadata.
PythonPrimitiveValue
Primitive Python-like values for metadata and validation helpers.
PythonReservedWord
A hard or soft reserved Python word.
PythonSoftKeyword
Python soft keywords used by pattern matching and newer syntax contexts.
PythonStringKind
Python string literal kind metadata.
PythonValueParseError
Error returned when Python value metadata labels are invalid.
PythonVersionFamily
Python version family label.
PythonVersionParseError
Error returned while parsing Python version metadata.
PythonVirtualEnvError
Error returned when virtual environment metadata is invalid.
PythonVirtualEnvKind
Python virtual environment manager kind.
UvCommand
Common uv command labels.
UvConfigFile
uv config file labels.
UvLockfile
uv lockfile labels.
UvProjectCommand
uv project subcommand labels.
UvPythonCommand
uv python subcommand labels.
UvTextError
Error returned when uv metadata text is invalid.
UvToolCommand
uv tool subcommand labels.

Functions§

is_ascii_python_identifier_continue
Returns whether character is accepted after the first identifier character.
is_ascii_python_identifier_start
Returns whether character is accepted as an ASCII Python identifier start.
is_dunder_name
Returns whether input looks like a Python dunder name such as __init__.
is_editable
Returns whether input looks like an editable install option.
is_private_name
Returns whether input looks like a single-underscore private name.
is_python_keyword
Returns whether input is a hard Python keyword.
is_python_reserved_word
Returns whether input is either a hard or soft Python reserved word.
is_python_soft_keyword
Returns whether input is a Python soft keyword.
is_requirements_file
Returns whether input looks like a requirements-file option.
is_valid_ascii_python_identifier
Returns whether input is an ASCII-safe Python identifier and not a hard keyword.