Smiles-Validator
A Pydantic validator for SMILES chemical notation that validates, sanitizes, and optionally returns either canonical or original input.
Install
pip install smiles-validator
Requires Python ≥ 3.12 · Pydantic v2 · RDKit 2024.9+
Usage
from pydantic import BaseModel
from typing import Annotated
from smiles_validator import SmilesText, SmilesValidator
class Model(BaseModel):
# Default: Canonical SMILES
canonical: SmilesText
# Keep original input
original: Annotated[str, SmilesValidator(keep_original=True)]
m = Model(
canonical="C1=CC=CC=C1",
original="C1=CC=CC=C1"
)
print(m.canonical) # => "c1ccccc1"
print(m.original) # => "C1=CC=CC=C1"
Features
- 🚀 Fast SMILES validation using RDKit
- 🔄 Canonicalization with optional original input preservation
- 📦 Pydantic v2 integration
- 📊 Comprehensive test coverage
- 🧪 CI/CD with multiple Python versions
API
SmilesValidator Class
SmilesValidator(keep_original: bool = False)
Parameters:
keep_original: IfTrue, returns the exact input string after validation. IfFalse(default), returns the canonical SMILES.
SmilesText Type
SmilesText is an alias for Annotated[str, SmilesValidator()] that automatically uses the default validator settings (canonical output).
Development
# Install dependencies
uv sync --locked --all-extras --dev
# Run tests
just test
# Run linting
just check
# Run formatting
just format
License
Acknowledgements
- Built with RDKit for chemical structure handling
- Uses Pydantic v2 for validation integration
Metadata
Release files for smiles-validator 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| smiles_validator-0.2.2.tar.gz | 5.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| smiles_validator-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.8 kB
Release files / smiles_validator-0.2.2.tar.gz
| Download URL | smiles_validator-0.2.2.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d68484a19af5df5543637dfea86b84742d3ea06d1e082513bca0efd0effb6da
|
|
BLAKE2b-256 checksum How to use checksums |
404461c318444f82e9d98b615f366c317f6a8f7b954280bdd2e9b9e0af246e9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Jun 5, 2025.
Transparency logRelease files / smiles_validator-0.2.2-py3-none-any.whl
| Download URL | smiles_validator-0.2.2-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bb114585397ac5293783b5bb8f8bb163d2b7116816c72bd2f31698bfc4db585
|
|
BLAKE2b-256 checksum How to use checksums |
8051bfced89229943d3813829b7de77fce0722c1b72f0e1e6857b1c519bf0982
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Jun 5, 2025.
Transparency log