Psycopg2
Psycopg is the most popular postgresql database adapter for the python programming language.
Psycopg2. Cursor execute a command. Psycopg2 postgresql client navicat premium psycopy2. This connection is thread safe and can be shared among many threads. 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.
Host is the ip address or the dns of the server where your database is located. Psycopg2 262 cp27 none winamd64whlscripts cmdpip install cpython27scriptspsycopg2 262 cp27 none winamd64whl. The following are important psycopg2 module routines which can suffice your requirement to work with postgresql database from your python program. 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.
Python psycopg2 module apis. Connect dbnametest userpostgres open a cursor to perform database operations cur conn. Psycopg2connect using the connect method we can create a connection to a postgresql database instance. Import psycopg2 connect to an existing database conn psycopg2.
User is a user with permissions. This creates a new table cur. You want to connect to the database you created earlier psycopgtest. The connect method accepts various arguments that we discussed above.
You used psycopg2connect to create the connection. In this case the host is your local machine or localhost. In our example we passed the following connection arguments to connect postgresql. Homepage download documentation issue tracker code statistics.
This returns a postgresql connection object. Homepage download documentation issue tracker code statistics. User postgres. This function accepts the following arguments.
Execute create table test id serial primary key num integer data varchar pass data to fill a query placeholders and let. Database is the name of the database to connect to. If you are looking for a more sophisticated application then you can look into python psycopg2 modules official documentation.