{"id":15998207,"url":"https://github.com/yushulx/python-twain-wia-sane-scanner","last_synced_at":"2025-03-18T01:31:28.731Z","repository":{"id":196929826,"uuid":"697145249","full_name":"yushulx/python-twain-wia-sane-scanner","owner":"yushulx","description":"A Python package for programming with Dynamsoft Service, supporting scanning documents from TWAIN, WIA, ICA, SANE and eSCL scanners.","archived":false,"fork":false,"pushed_at":"2024-10-10T08:29:15.000Z","size":46,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-21T22:38:16.549Z","etag":null,"topics":["document","escl","ica","python","sane","scanner","twain","wia"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/twain-wia-sane-scanner/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yushulx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-27T06:36:19.000Z","updated_at":"2024-10-10T08:29:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"724a4999-865a-4ad9-b786-720e6f4aafcd","html_url":"https://github.com/yushulx/python-twain-wia-sane-scanner","commit_stats":null,"previous_names":["yushulx/twain-wia-sane-scanner"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yushulx%2Fpython-twain-wia-sane-scanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yushulx%2Fpython-twain-wia-sane-scanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yushulx%2Fpython-twain-wia-sane-scanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yushulx%2Fpython-twain-wia-sane-scanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yushulx","download_url":"https://codeload.github.com/yushulx/python-twain-wia-sane-scanner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243894412,"owners_count":20365026,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["document","escl","ica","python","sane","scanner","twain","wia"],"created_at":"2024-10-08T08:08:03.660Z","updated_at":"2025-03-18T01:31:28.482Z","avatar_url":"https://github.com/yushulx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Document Scanner for TWAIN, WIA, SANE, ICA, and eSCL\nThe package provides methods for calling [Dynamsoft Service REST APIs](https://www.dynamsoft.com/blog/announcement/dynamsoft-service-restful-api/). This allows developers to build Python applications for digitizing documents from **TWAIN (32-bit/64-bit)**, **WIA**, **SANE**, **ICA** and **eSCL** scanners.\n\n## Prerequisites\n1. Install Dynamsoft Service.\n    - Windows: [Dynamsoft-Service-Setup.msi](https://demo.dynamsoft.com/DWT/DWTResources/dist/DynamsoftServiceSetup.msi)\n    - macOS: [Dynamsoft-Service-Setup.pkg](https://demo.dynamsoft.com/DWT/DWTResources/dist/DynamsoftServiceSetup.pkg)\n    - Linux: \n        - [Dynamsoft-Service-Setup.deb](https://demo.dynamsoft.com/DWT/DWTResources/dist/DynamsoftServiceSetup.deb)\n        - [Dynamsoft-Service-Setup-arm64.deb](https://demo.dynamsoft.com/DWT/DWTResources/dist/DynamsoftServiceSetup-arm64.deb)\n        - [Dynamsoft-Service-Setup-mips64el.deb](https://demo.dynamsoft.com/DWT/DWTResources/dist/DynamsoftServiceSetup-mips64el.deb)\n        - [Dynamsoft-Service-Setup.rpm](https://demo.dynamsoft.com/DWT/DWTResources/dist/DynamsoftServiceSetup.rpm)\n        \n2. Request a [free trial license](https://www.dynamsoft.com/customer/license/trialLicense?product=dwt).\n\n## Dynamsoft Service REST API\nBy default, the REST API's host address is set to `http://127.0.0.1:18622`. \n\n| Method | Endpoint        | Description                   | Parameters                         | Response                      |\n|--------|-----------------|-------------------------------|------------------------------------|-------------------------------|\n| GET    | `/DWTAPI/Scanners`    | Get a list of scanners  | None                               | `200 OK` with scanner list       |\n| POST   | `/DWTAPI/ScanJobs`    | Creates a scan job      | `license`, `device`, `config`      | `201 Created` with job ID    |\n| GET    | `/DWTAPI/ScanJobs/:id/NextDocument`| Retrieves a document image     | `id`: Job ID   | `200 OK` with image stream    |\n| DELETE | `/DWTAPI/ScanJobs/:id`| Deletes a scan job       | `id`: Job ID                      | `200 OK`              |\n\nYou can navigate to `http://127.0.0.1:18625/` to access the service. To make it accessible from desktop, mobile, and web applications on the same network, you can change the host address to a LAN IP address. For example, you might use `http://192.168.8.72`.\n\n![dynamsoft-service-config](https://github.com/yushulx/dynamsoft-service-REST-API/assets/2202306/e2b1292e-dfbd-4821-bf41-70e2847dd51e)\n\nThe scanner parameter configuration is based on [Dynamsoft Web TWAIN documentation](https://www.dynamsoft.com/web-twain/docs/info/api/Interfaces.html#DeviceConfiguration). \n\n## Quick Start\nReplace the license key in the code below with a valid one and run the code.\n\n```python\nfrom dynamsoftservice import ScannerController, ScannerType\n\nscannerController = ScannerController()\ndevices = []\nhost = \"http://127.0.0.1:18622\"\nlicense_key = \"LICENSE-KEY\"\n\nquestions = \"\"\"\nPlease select an operation:\n1. Get scanners\n2. Acquire documents by scanner index\n3. Quit\n\"\"\"\n\n\ndef ask_question():\n    while True:\n        print(\".............................................\")\n        answer = input(questions)\n\n        if answer == '3':\n            break\n        elif answer == '1':\n            scanners = scannerController.getDevices(\n                host, ScannerType.TWAINSCANNER | ScannerType.TWAINX64SCANNER)\n            devices.clear()\n            for i, scanner in enumerate(scanners):\n                devices.append(scanner)\n                print(f\"\\nIndex: {i}, Name: {scanner['name']}\")\n        elif answer == '2':\n            if len(devices) == 0:\n                print(\"Please get scanners first!\\n\")\n                continue\n\n            index = input(f\"\\nSelect an index (\u003c= {len(devices) - 1}): \")\n            index = int(index)  \n\n            if index \u003c 0 or index \u003e= len(devices):\n                print(\"It is out of range.\")\n                continue\n\n            parameters = {\n                \"license\": license_key,\n                \"device\": devices[index][\"device\"],\n            }\n\n            parameters[\"config\"] = {\n                \"IfShowUI\": False,\n                \"PixelType\": 2,\n                \"Resolution\": 200,\n                \"IfFeederEnabled\": False,\n                \"IfDuplexEnabled\": False,\n            }\n\n            job_id = scannerController.scanDocument(host, parameters)\n\n            if job_id != \"\":\n                images = scannerController.getImageFiles(host, job_id, \"./\")\n                for i, image in enumerate(images):\n                    print(f\"Image {i}: {image}\")\n\n                scannerController.deleteJob(host, job_id)\n        else:\n            continue\n\n\nif __name__ == \"__main__\":\n    ask_question()\n```\n\n## Example\n- [Flet App](https://github.com/yushulx/twain-wia-sane-scanner/tree/main/example)\n\n    ![python-flet-twain-document-scanner](https://github.com/yushulx/twain-wia-sane-scanner/assets/2202306/219d2adc-b03c-4da7-8393-10f49cdbc54d)\n\n## DynamsoftService API\nThe `DynamsoftService` class provides methods to interact with the Dynamsoft service.\n\n- `getDevices(self, host: str, scannerType: int = None) -\u003e List[Any]`: Get a list of available devices.\n- `scanDocument(self, host: str, parameters: Dict[str, Any]) -\u003e str`: Scan a document.\n- `deleteJob(self, host: str, jobId: str) -\u003e None`: Delete a job.\n- `getImageFile(self, host, job_id, directory)`: Get an image file.\n- `getImageFiles(self, host: str, jobId: str, directory: str) -\u003e List[str]`: Get a list of image files.\n- `getImageStreams(self, host: str, jobId: str) -\u003e List[bytes]`: Get a list of image streams.\n\n## How to Build the Package\n- Source distribution:\n    \n    ```bash\n    python setup.py sdist\n    ```\n\n- Wheel:\n    \n    ```bash\n    pip wheel . --verbose\n    # Or\n    python setup.py bdist_wheel\n    ```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyushulx%2Fpython-twain-wia-sane-scanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyushulx%2Fpython-twain-wia-sane-scanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyushulx%2Fpython-twain-wia-sane-scanner/lists"}