Python Package Distribution
Relevant source files
The following files were used as context for generating this wiki page:
The Python package distribution for mb_capcha_ocr is designed to provide a lightweight, installable library for performing Optical Character Recognition (OCR) on MBBank CAPTCHAs. It encapsulates complex neural network inference into a simple API, allowing users to integrate CAPTCHA solving capabilities into other Python applications with minimal configuration.
Sources: setup.py:12-14, README.md:3-5
Metadata and Packaging Configuration
The project utilizes setuptools to manage the distribution process. The configuration ensures that the package includes not only the source code but also the necessary pre-trained model files and dependency specifications required for production environments.
Package Metadata
The setup.py file defines the identity and environmental requirements of the library. It dynamically pulls the version number from the package's internal initialization file to ensure consistency across the codebase.
| Field | Value / Source | Description |
|---|---|---|
| Name | mb_capcha_ocr | The distribution name for PyPI/pip. |
| Version | Extracted from __init__.py | Current version (e.g., 0.1.6). |
| License | MIT | Permissive open-source license. |
| Description | Pytorch OCR base library for MBBank | Short project summary. |
| Long Description | Content of README.md | Detailed documentation for the package. |
| Author | The DT | Project maintainer. |
Sources: setup.py:12-25, mb_capcha_ocr/__init__.py:3
Dependency Management
The distribution separates runtime dependencies from training dependencies. The runtime environment is kept lean by focusing on inference-only libraries like onnxruntime instead of the full torch stack.
The diagram shows the logical components included in the distributed package to ensure immediate usability upon installation.
Sources: requirements.txt:1-5, setup.py:26-28
Distribution Structure and Assets
The package structure is organized to ensure that the pre-trained ONNX model is accessible to the inference logic after installation.
Resource Inclusion
Unlike standard Python packages that only include .py files, this distribution specifically includes the model.onnx file as package data. This allows the OcrModel class to locate the model using relative paths within the installed site-packages directory.
- Package Root:
mb_capcha_ocr/ - Core Modules:
predict.py,__init__.py - Static Assets:
model.onnx(defined inpackage_data)
Sources: setup.py:25-27, mb_capcha_ocr/predict.py:10
Initialization Logic
The __init__.py file serves as the entry point for the library, exposing the primary OcrModel class to the top-level namespace. This simplifies the import statement for end-users.
from .predict import OcrModel
__version__ = "0.1.6"
Sources: mb_capcha_ocr/__init__.py:1-3
Installation and Runtime Flow
The package distribution supports standard installation via pip. Once installed, the library handles the internal pathing to its binary assets automatically.
This diagram illustrates how the distributed components interact during a standard execution flow.
Sources: README.md:46-52, mb_capcha_ocr/predict.py:14-18
Summary of Requirements
The following table outlines the specific software requirements defined in the distribution configuration for running the package:
| Requirement | Module Usage | File Source |
|---|---|---|
onnxruntime | Executing the .onnx model | requirements.txt |
pillow | Image loading and preprocessing | requirements.txt |
numpy | Matrix manipulation and argmax | requirements.txt |
setuptools / wheel | Packaging and distribution builds | requirements.txt |
Sources: requirements.txt:1-5, setup.py:5-10