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.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: 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

Releasing New Versions

This repository uses GitHub Actions for automated releases and PyPI publishing. To create a new release:

  1. Create a new tag in the format vX.Y.Z:
git tag v1.0.0
  1. 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

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.1.14.tar.gz (5.5 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.1.14-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smiles_validator-0.1.14.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

Hashes for smiles_validator-0.1.14.tar.gz
Algorithm Hash digest
SHA256 c40b21132286abd3539ac40bcfaebce68968f67dee6f87fb4964a4d0e20edbed
MD5 d74d721fa41cc88c33728d23e7a07646
BLAKE2b-256 cde82cc171df0cfbee2e6799a9aa40a9e885466a7559ac55ff89fa8c11950eec

See more details on using hashes here.

Provenance

The following attestation bundles were made for smiles_validator-0.1.14.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.1.14-py3-none-any.whl.

File metadata

File hashes

Hashes for smiles_validator-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 9f3c04475367ba6b1fe019ffd45b611cc7a2cd096d786cb1278c221301bac263
MD5 518bfbd86c4eac04102421faf541463f
BLAKE2b-256 f40afd1f3457a23299f4abca2a1f7cc9c729bb72be86c592543a18bb571d1109

See more details on using hashes here.

Provenance

The following attestation bundles were made for smiles_validator-0.1.14-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