A comprehensive digital transformation has been undergone by the oil and gas industry, wherein digital twins are leveraged to enable real-time data analysis, providing predictive and diagnostic engineering insights. The potential for developing intelligent oil and gas fields is substantial with the implementation of digital twins. A digital twin framework for gear rack drilling rigs is proposed, built upon an understanding of the digital twin composition and characteristics of the gear rack drilling rig lifting system. The framework encompasses descriptions of digital twin characteristics specific to drilling rigs, the application environment, and behavioral rules. The modeling approach integrates mechanism modeling, real-time performance response, instantaneous data transmission, and data visualization. To illustrate this framework, exemplary case studies involving the transmission unit and support unit of the lifting system are presented. Mechanism models are constructed to analyze dynamic gear performance and support unit response. Real-time data transmission is facilitated through sensor-based monitoring, enhancing the prediction speed and accuracy of dynamic performance through a synergy of mechanism modeling, machine learning, and real-time data analysis. The digital twin of the lifting system is visualized utilizing the Unity3D platform. Furthermore, functionalities on data acquisition, processing, and visualization across diverse application scenarios are encapsulated into modular components, streamlining the creation of high-fidelity digital twins. The frameworks and modeling methodologies presented herein can serve as a foundational and methodological guide for the exploration and implementation of digital twin technology within the oil and gas industry, ultimately fostering its advancement in this sector.