Skip to main content

Pydantic validator for SMILES chemical notation: validates, sanitizes, and optionally returns canonical or original input

Project description

Smiles-Validator

Test Coverage Python PyPI version License CI Code Style

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: If True, returns the exact input string after validation. If False (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

MIT License · GitHub

Acknowledgements

  • Built with RDKit for chemical structure handling
  • Uses Pydantic v2 for validation integration

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

smiles_validator-0.2.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

smiles_validator-0.2.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file smiles_validator-0.2.1.tar.gz.

File metadata

  • Download URL: smiles_validator-0.2.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for smiles_validator-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d7e1f265170c2215d5994d13f5f009f88c268d43358a5d686a9c6e56916722f7
MD5 a2f33281174b39dfbfa081c3f21bb0a9
BLAKE2b-256 a0dadd8c3b44ba767b20de4f65471fc4a3ebfd6a245ffde61ca050e2b399b573

See more details on using hashes here.

Provenance

The following attestation bundles were made for smiles_validator-0.2.1.tar.gz:

Publisher: release.yml on scriptogre/smiles-validator

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

File details

Details for the file smiles_validator-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for smiles_validator-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 19f67d6ff66984dff5341cd21176899bc3dee19c9112fb5db78b08b571d4f29f
MD5 fb63a196be1cb8e7826ba2e539aedf5e
BLAKE2b-256 61eba605b6c559a60ff9b469bf77d512803d5e7096730fe25cb730d0afb60d06

See more details on using hashes here.

Provenance

The following attestation bundles were made for smiles_validator-0.2.1-py3-none-any.whl:

Publisher: release.yml on scriptogre/smiles-validator

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