Psycopg : module Python pour PostgreSQL

AttentionPilote de SGBD

Un langage de programmation a besoin d'un pilote (driver) spécifique pour interagir avec un SGBD. L'usage de ce pilote varie selon les langages et les pilotes, mais c'est une opération simple consistant à ajouter un librairie à son programme.

Définition

Pour connecter Python et PostgreSQL, il existe plusieurs pilotes (modules Python), on utilisera dans le cadre de ce cours le pilote Psycopg2.

Psycopg is a PostgreSQL adapter for the Python programming language. It is a wrapper for the libpq, the official PostgreSQL client library.

Syntaxe

1
#!/usr/bin/python3
2
import psycopg2

FondamentalDocumentation

MéthodeInstallation

1
pip3 install --user psycopg2-binary

ComplémentPour mettre à jour pip3

1
pip3 install --user --upgrade pip

ComplémentPour installer pip3 sous Debian

1
apt-get install python3-pip