Pydantic validator for SMILES chemical notation: validates, sanitizes, and optionally returns canonical or original input
Project description
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.10 · 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
Releasing New Versions
This repository uses GitHub Actions for automated releases and PyPI publishing. To create a new release:
- Create a new tag in the format
vX.Y.Z:
git tag v1.0.0
- Push the tag to GitHub:
git push --tags
The GitHub Actions workflow will automatically:
- Build the package
- Create a GitHub release
- Publish to PyPI
License
Acknowledgements
- Built with RDKit for chemical structure handling
- Uses Pydantic v2 for validation integration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smiles_validator-0.1.13.tar.gz.
File metadata
- Download URL: smiles_validator-0.1.13.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa6bc0a559e1d7b8bbbc68e60cb6251375b1899857be20afcde37fa8ca870bc6
|
|
| MD5 |
5d9216eebf87d88560a6e76b08749bcb
|
|
| BLAKE2b-256 |
cd714b70ee0dc272d887fa818bb9e2762e37f1e7d7347d0429556420e30a45a0
|
Provenance
The following attestation bundles were made for smiles_validator-0.1.13.tar.gz:
Publisher:
release.yml on scriptogre/smiles-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smiles_validator-0.1.13.tar.gz -
Subject digest:
fa6bc0a559e1d7b8bbbc68e60cb6251375b1899857be20afcde37fa8ca870bc6 - Sigstore transparency entry: 215798195
- Sigstore integration time:
-
Permalink:
scriptogre/smiles-validator@17f095c581352e2739068a675be07d9f6128d0eb -
Branch / Tag:
refs/tags/v0.1.13 - Owner: https://github.com/scriptogre
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@17f095c581352e2739068a675be07d9f6128d0eb -
Trigger Event:
push
-
Statement type:
File details
Details for the file smiles_validator-0.1.13-py3-none-any.whl.
File metadata
- Download URL: smiles_validator-0.1.13-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d02fda18bfb04d8bc79f0604fe69d8f224126e3674ec897011e80b79238ba142
|
|
| MD5 |
222332d973164261d000da74ffb1c080
|
|
| BLAKE2b-256 |
a8ba5e4851e4457295cdffb9cd60212fe437ebf590d10e64345ec4ae5d7b7f3c
|
Provenance
The following attestation bundles were made for smiles_validator-0.1.13-py3-none-any.whl:
Publisher:
release.yml on scriptogre/smiles-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smiles_validator-0.1.13-py3-none-any.whl -
Subject digest:
d02fda18bfb04d8bc79f0604fe69d8f224126e3674ec897011e80b79238ba142 - Sigstore transparency entry: 215798199
- Sigstore integration time:
-
Permalink:
scriptogre/smiles-validator@17f095c581352e2739068a675be07d9f6128d0eb -
Branch / Tag:
refs/tags/v0.1.13 - Owner: https://github.com/scriptogre
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@17f095c581352e2739068a675be07d9f6128d0eb -
Trigger Event:
push
-
Statement type: