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_REGISTRYIMAGE_CAP_REGISTRYGENERAL_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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
590df286265306ae787a9efedb30ef7b11ce2ec5d12e576dff7a25d7bdd2f1ed
|
|
| MD5 |
4cdf6ed97f17676e58edd3166ba3b5aa
|
|
| BLAKE2b-256 |
553acea652b615f95d7618f14dd830e4b6b49956fa351cdbf67ccd7bf57984bd
|
Provenance
The following attestation bundles were made for pytwain_extensions-0.1.0.tar.gz:
Publisher:
publish.yml on costa-jonathan/pytwain-extensions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytwain_extensions-0.1.0.tar.gz -
Subject digest:
590df286265306ae787a9efedb30ef7b11ce2ec5d12e576dff7a25d7bdd2f1ed - Sigstore transparency entry: 749394284
- Sigstore integration time:
-
Permalink:
costa-jonathan/pytwain-extensions@85fc763d57d0301f9214d3cb493652ff27fbfabf -
Branch / Tag:
refs/heads/main - Owner: https://github.com/costa-jonathan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@85fc763d57d0301f9214d3cb493652ff27fbfabf -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pytwain_extensions-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytwain_extensions-0.1.0-py3-none-any.whl
- Upload date:
- Size: 44.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c26bd263c4b974aa5742252d0b517dcb1ba57d7f6dba7db598c73b4fecce651c
|
|
| MD5 |
d6930550fa3776b31eb5d242b12a6cdb
|
|
| BLAKE2b-256 |
5d5c9dd0466a268f78ab7b9fd33ee83f6f9fa128a54fef2119c8defc804e7eab
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytwain_extensions-0.1.0-py3-none-any.whl -
Subject digest:
c26bd263c4b974aa5742252d0b517dcb1ba57d7f6dba7db598c73b4fecce651c - Sigstore transparency entry: 749394324
- Sigstore integration time:
-
Permalink:
costa-jonathan/pytwain-extensions@85fc763d57d0301f9214d3cb493652ff27fbfabf -
Branch / Tag:
refs/heads/main - Owner: https://github.com/costa-jonathan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@85fc763d57d0301f9214d3cb493652ff27fbfabf -
Trigger Event:
workflow_dispatch
-
Statement type: