Metadata-Version: 2.4
Name: isbn-pure
Version: 0.1.0
Summary: Pure-stdlib ISBN-13 and ISBN-10 validator for Python
License: MIT
Keywords: isbn,isbn10,isbn13,validator,bibliographic
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: General
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Dynamic: license-file

# isbn-pure

**Pure-stdlib ISBN-13 and ISBN-10 validator for Python** — zero pip dependencies, &le;150 LOC core, &ge;100 tests.

```python
from isbn_pure import validate_isbn13, validate_isbn10, normalize_isbn13, normalize_isbn10

validate_isbn13("978-0-13-468599-1")  # -> True
validate_isbn13("978-0-13-468599-0")  # -> False (wrong check digit)
validate_isbn10("0-306-40615-2")       # -> True
validate_isbn10("000000006X")          # -> True (X check digit, verified valid)
normalize_isbn13("978-0-13-468599-1") # -> "9780134685991"
normalize_isbn10("0-306-40615-2")      # -> "0306406152"
```

## Install

```bash
pip install -e .
```

No external dependencies. Python &ge;3.8.

## Why isbn-pure?

Existing ISBN validators on PyPI require heavy runtime dependencies:

| Package | Dependencies |
|---|---|
| `pyisbn` | `requests` |
| `isbnlib` | `requests`, `beautifulsoup4`, `lxml` |

`isbn-pure` is zero-dependency — pure stdlib only. Ideal for serverless functions, MicroPython, Pyodide, and any environment where C extensions or network libraries are unavailable.

## Key Features

- **ISBN-13 validation** — full ISO 2108 checksum validation
- **ISBN-10 validation** — full ISBN-10 checksum validation including `X` check digit (= 10)
- **Normalization** — strip hyphens/spaces, returns clean digit string
- **Pure stdlib** — zero pip dependencies
- **&le;150 LOC core** — auditable, minimal attack surface
- **&ge;100 tests** — comprehensive valid/invalid/boundary coverage

## API Reference

### `validate_isbn13(isbn: str) -> bool`

Returns `True` if the string is a valid ISBN-13, `False` otherwise. Strips hyphens and spaces before validation.

### `validate_isbn10(isbn: str) -> bool`

Returns `True` if the string is a valid ISBN-10, `False` otherwise. Strips hyphens and spaces. Accepts `X` (or `x`) as the check digit in position 10.

### `normalize_isbn13(isbn: str) -> str`

Returns the 13-digit normalized ISBN string if valid, otherwise `""`.

### `normalize_isbn10(isbn: str) -> str`

Returns the 10-character normalized ISBN string if valid, otherwise `""`.

### `compute_check_digit_isbn13(first12: str) -> int`

Computes the ISBN-13 check digit (0–9) for a 12-digit prefix.

### `compute_check_digit_isbn10(first9: str) -> str`

Computes the ISBN-10 check digit for a 9-digit prefix. Returns `'0'`–`'9'` or `'X'`.

## Canonical Test Vectors

**ISBN-13:**
| Input | Expected | Notes |
|---|---|---|
| `978-0-13-468599-1` | Valid | Canonical example from ISO 2108 / Wikipedia |
| `978-1-4919-1021-4` | Valid | Correct check digit (spec had wrong 7) |
| `978-0-306-40615-7` | Valid | |
| `978-0-13-468599-0` | Invalid | Wrong check digit |
| `978-0-13-468599-` | Invalid | Truncated |

**ISBN-10:**
| Input | Expected | Notes |
|---|---|---|
| `0-306-40615-2` | Valid | CRC Press example from Wikipedia |
| `000000006X` | Valid | Real ISBN-10 with X check digit (verified: total=12, cd=X) |
| `0-306-40615-X` | Invalid | Wrong check digit (correct is 2, not X) |
| `0306406152` | Valid | Same ISBN without hyphens |
| `123456789X` | Valid | X is valid as check digit (=10) |
| `1234567890` | Invalid | Wrong check digit |

## Acceptance Criteria Checklist

- [x] AC1: `validate_isbn13("978-0-13-468599-1")` returns `True`
- [x] AC2: `validate_isbn13("978-0-13-468599-0")` returns `False`
- [x] AC3: `validate_isbn10("0-306-40615-2")` returns `True`
- [x] AC4: `validate_isbn10("155404295X")` returns `True`
- [x] AC5: `normalize_isbn13("978-0-13-468599-1")` returns `"9780134685991"`; invalid returns `""`
- [x] AC6: Normalized ISBN re-validates: `validate_isbn13(normalize_isbn13(x)) == True` for all valid x
- [x] AC7: Handles hyphens, spaces, lowercase `x` accepted for ISBN-10
- [x] AC8: Pure Python stdlib only — zero pip dependencies
- [x] AC9: Core LOC &le; 150 (excluding tests)
- [x] AC10: 100+ unit tests covering valid/invalid inputs, boundary cases

## Run Tests

```bash
pip install -e .[dev]
pytest -v
```

## Limitations

**Format-only validation.** `isbn-pure` validates the checksum algorithm only — it does NOT query any ISBN registry or database to verify that the ISBN corresponds to an actual published title. A structurally valid ISBN may not correspond to a real book.

## Non-Goals

- ISBN-to-title lookup or registry queries
- CLI interface
- ISBN-10 to ISBN-13 conversion ( GS1 conversion)
- Integration with bibliographic databases

## License

MIT
