项目简介
本项目是openGauss的Python驱动,借助psycopg2这个广受欢迎的PostgreSQL数据库适配器,实现Python与openGauss数据库的交互。该驱动完整实现了Python DB API 2.0规范,具备线程安全特性,适合高并发多线程应用场景。同时还包含了用于验证psycopg2库功能的测试套件,可确保驱动在各种场景下都能正确工作。
项目的主要特性和功能
- Python DB API 2.0规范实现:完整遵循Python DB API 2.0规范,方便开发者进行数据库操作。
- 线程安全:支持多个线程共享同一连接,适用于多线程应用。
- 丰富的功能特性:具备客户端和服务器端游标、异步通信和通知、“COPY TO/COPY FROM”支持等功能。
- 数据类型适配:支持多种Python类型,并能与PostgreSQL数据类型进行匹配和适配。
- 测试套件完善:涵盖数据库连接、事务处理、游标操作、数据类型转换、复制功能、通知机制等多方面的测试,确保驱动功能的正确性和稳定性。
安装使用步骤
打包步骤
- 推荐使用python3,请在服务器上装python3和python3-devel:
yum install python3 python3-devel
- python驱动的打包需要依赖openGauss-server编译的libpq,请参照 openGauss使用命令编译代码
- 下载
openGauss-connector-python-psycopg2
仓库代码,进入到根目录下,执行:sh build.sh -bd /data/compile/openGauss-server/dest/ -v 5.0.0
说明 -bd: 指定openGauss数据库构建结果目录 -v: 指定构建包的版本号。不指定则默认为5.0.0
编译完成后的驱动,在 output
目录下。
软件下载
社区每日构建,提供三套环境已经编译好的驱动包供使用,下载路径如下:
其中 VERSION 为当前最新的版本号。
openEuler-aarch64: https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/arm/openGauss-VERSION-openEuler-aarch64-Python.tar.gz
CentOS-x86_64: https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/x86/openGauss-VERSION-CentOS-x86_64-Python.tar.gz
openEuler-x86_64: https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/x86_openEuler/openGauss-VERSION-openEuler-x86_64-Python.tar.gz
Psycopg2安装
Building Psycopg requires a few prerequisites (a C compiler, some development packages): please check the install_ and the faq_ documents in the doc
dir or online for the details.
If prerequisites are met, you can install psycopg like any other Python package, using pip
to download it from PyPI_::
$ pip install psycopg2
or using setup.py
if you have downloaded the source package locally::
$ python setup.py build
$ sudo python setup.py install
You can also obtain a stand-alone package, not requiring a compiler or external libraries, by installing the psycopg2-binary
_ package from PyPI::
$ pip install psycopg2-binary
The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.
.. _PyPI: https://pypi.org/project/psycopg2/ .. _psycopg2-binary: https://pypi.org/project/psycopg2-binary/ .. _install: https://www.psycopg.org/docs/install.html#install-from-source .. _faq: https://www.psycopg.org/docs/faq.html#faq-compile
下载地址
点击下载 【提取码: 4003】【解压密码: www.makuang.net】