Package: twain-wia-sane-scanner
Python Document Scanner for TWAIN, WIA, SANE, ICA, and eSCLThe package provides methods for callingDynamsoft Service REST APIs. This allows developers to build Python applications for digitizing documents fromTWAIN (32-bit/64-bit),WIA,SANE,ICAandeSCLscanners.PrerequisitesInstall Dynamsoft Service.Windows:Dynamsoft-Service-Setup.msimacOS:Dynamsoft-Service-Setup.pkgLinux:Dynamsoft-Service-Setup.debDynamsoft-Service-Setup-arm64.debDynamsoft-Service-Setup-mips64el.debDynamsoft-Service-Setup.rpmRequest afree trial license.Dynamsoft Service REST APIBy default, the REST API's host address is set tohttp://127.0.0.1:18622.MethodEndpointDescriptionParametersResponseGET/DWTAPI/ScannersGet a list of scannersNone200 OKwith scanner listPOST/DWTAPI/ScanJobsCreates a scan joblicense,device,config201 Createdwith job IDGET/DWTAPI/ScanJobs/:id/NextDocumentRetrieves a document imageid: Job ID200 OKwith image streamDELETE/DWTAPI/ScanJobs/:idDeletes a scan jobid: Job ID200 OKYou can navigate tohttp://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 usehttp://192.168.8.72.The scanner parameter configuration is based onDynamsoft Web TWAIN documentation.Quick StartReplace the license key in the code below with a valid one and run the code.fromdynamsoftserviceimportScannerController,ScannerTypescannerController=ScannerController()devices=[]host="http://127.0.0.1:18622"license_key="LICENSE-KEY"questions="""Please select an operation:1. Get scanners2. Acquire documents by scanner index3. Quit"""defask_question():whileTrue:print(".............................................")answer=input(questions)ifanswer=='3':breakelifanswer=='1':scanners=scannerController.getDevices(host,ScannerType.TWAINSCANNER|ScannerType.TWAINX64SCANNER)devices.clear()fori,scannerinenumerate(scanners):devices.append(scanner)print(f"\nIndex:{i}, Name:{scanner['name']}")elifanswer=='2':iflen(devices)==0:print("Please get scanners first!\n")continueindex=input(f"\nSelect an index (<={len(devices)-1}): ")index=int(index)ifindex<0orindex>=len(devices):print("It is out of range.")continueparameters={"license":license_key,"device":devices[index]["device"],}parameters["config"]={"IfShowUI":False,"PixelType":2,"Resolution":200,"IfFeederEnabled":False,"IfDuplexEnabled":False,}job_id=scannerController.scanDocument(host,parameters)ifjob_id!="":images=scannerController.getImageFiles(host,job_id,"./")fori,imageinenumerate(images):print(f"Image{i}:{image}")scannerController.deleteJob(host,job_id)else:continueif__name__=="__main__":ask_question()ExampleFlet AppDynamsoftService APITheDynamsoftServiceclass provides methods to interact with the Dynamsoft service.getDevices(self, host: str, scannerType: int = None) -> List[Any]: Get a list of available devices.scanDocument(self, host: str, parameters: Dict[str, Any]) -> str: Scan a document.deleteJob(self, host: str, jobId: str) -> None: Delete a job.getImageFile(self, host, job_id, directory): Get an image file.getImageFiles(self, host: str, jobId: str, directory: str) -> List[str]: Get a list of image files.getImageStreams(self, host: str, jobId: str) -> List[bytes]: Get a list of image streams.How to Build the PackageSource distribution:pythonsetup.pysdistWheel:pipwheel.--verbose# Orpythonsetup.pybdist_wheel