Skip to main content

A Python library that extends pytwain with pythonic design to make working with the TWAIN api easier. Built on TWAIN 2.5 specification.

Project description

Twain Extensions

Twain Extensions is a Python library designed to enhance usability of the pytwain library with a pytonic design layered on top of the existing functionality.

Features

  • Capability Registries: Predefined registries for audio, image, and general capabilities including documentation from the TWAIN specification.
  • Dynamic Code Generation: Can generate a pydantic model for the configuration of a given scanner using Jinja2 templates.
  • Enhanced Data Types: Translates TWAIN specific enums and frames into pythonicly typed variables.

Groups

The library offers grouped installation of dependencies for different use cases:

  • twain_extensions: Installs the core library with enums and registries. No additional dependencies.
  • twain_extensions[dev]: Includes all development dependencies such as testing and linting tools.
  • twain_extensions[generate]: Includes dependencies required for code generation features.

Installation

To install the required dependencies, I recommend using uv.

uv sync --all-groups

Usage

Generating Scanner Models

You can generate a Python model for a scanner configuration using the generate_scanner_model function:

from twain_extensions.generate.generate import generate_scanner_model

source = twain.Source("Your Scanner Name")
generate_scanner_model(source, "output_file.py")

Capability Registries

The library includes predefined registries for various TWAIN capabilities:

  • AUDIO_CAP_REGISTRY
  • IMAGE_CAP_REGISTRY
  • GENERAL_CAP_REGISTRY

Project Structure

.
├── src/
│   ├── twain_extensions/
│   │   ├── enums.py
│   │   ├── frame.py
│   │   ├── generate/
│   │   │   ├── generate.py
│   │   │   ├── template.py
│   │   ├── registries/
│   │   │   ├── audio_capabilities.py
│   │   │   ├── capability.py
│   │   │   ├── general_capabilities.py
│   │   │   ├── image_capabilities.py
├── tests/
│   ├── test_registries.py
│   ├── test_registry_entries.py

Development

Running Tests

To run the tests, use:

pytest

Linting

This project uses Ruff for linting. To check for linting errors, run:

ruff check .

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Acknowledgments & Copyrights

This software is an implementation of the TWAIN specification.

  • TWAIN (Classic) Specification: © 1991-2025 TWAIN Working Group. All rights reserved.

  • Portions of the documentation strings in this library are quoted directly from the TWAIN Specification to assist developers. These descriptions remain the intellectual property of the TWAIN Working Group.

  • For more information, visit twain.org.

Contact

For any questions or feedback, please contact Jonathan Costa at jonathanleonhard.costa@gmail.com.

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

pytwain_extensions-0.1.0.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

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

pytwain_extensions-0.1.0-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file pytwain_extensions-0.1.0.tar.gz.

File metadata

  • Download URL: pytwain_extensions-0.1.0.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytwain_extensions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 590df286265306ae787a9efedb30ef7b11ce2ec5d12e576dff7a25d7bdd2f1ed
MD5 4cdf6ed97f17676e58edd3166ba3b5aa
BLAKE2b-256 553acea652b615f95d7618f14dd830e4b6b49956fa351cdbf67ccd7bf57984bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytwain_extensions-0.1.0.tar.gz:

Publisher: publish.yml on costa-jonathan/pytwain-extensions

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

File details

Details for the file pytwain_extensions-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytwain_extensions-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c26bd263c4b974aa5742252d0b517dcb1ba57d7f6dba7db598c73b4fecce651c
MD5 d6930550fa3776b31eb5d242b12a6cdb
BLAKE2b-256 5d5c9dd0466a268f78ab7b9fd33ee83f6f9fa128a54fef2119c8defc804e7eab

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytwain_extensions-0.1.0-py3-none-any.whl:

Publisher: publish.yml on costa-jonathan/pytwain-extensions

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