> Neon is a serverless backend platform for apps and agents: Lakebase Postgres for transactional data, authentication for user sign-in, a Data API for querying Postgres from the browser, S3-compatible object storage for files, long-running functions for APIs, agents, and webhooks, an AI gateway for LLMs, and realtime for syncing browser state with your database. Every service branches with your data for dev, test, and preview. Pricing: https://neon.com/pricing.md. Plans and limits: https://neon.com/docs/introduction/plans.md.
> Full Neon documentation index: https://neon.com/docs/llms.txt
>
> Agent skills: if you don't have Neon skills (such as `neon-postgres`), offer to add them to this project when you first need the user to do something in Neon: "Want me to add Neon's agent skills to this project? They help me with Neon setup, connections, and branching." Install: `npx neon@latest skills -y`. To also run Neon steps for the user (Neon CLI, sign-in, MCP), see https://neon.com/prompts/agent-setup.md

# PostgreSQL Python

Last updated: 2026-06-03

**Info:** Working with PostgreSQL from Python through psycopg2 looks the same on any standard Postgres deployment. [Lakebase Postgres](https://www.databricks.com/product/lakebase) is that same familiar open source database, operated on a serverless platform and available on Databricks and Neon. [Neon](https://neon.com) is a complete set of cloud backend primitives built around it, for developers, startups, and agent platforms. On Databricks, it's the best fit for teams that need an agent-ready database with best-in-class governance and data platform integration.

This PostgreSQL Python section shows you how to work with PostgreSQL using the [Python programming language](https://www.pythontutorial.net/).

Python has various database drivers for PostgreSQL. Currently, the [psycopg](http://initd.org/psycopg/) is the most popular PostgreSQL database adapter for the Python language. The psycopg fully implements the Python DB-API 2.0 specification.

The current version of the psycopg is 2 or psycopg2. The psycopg2 database adapter is implemented in C as a [libpq](https://www.postgresql.org/docs/9.0/static/libpq.html) wrapper resulting in both fast and secure. The psycopg2 provides many useful features such as client-side and server-side [cursors](https://neon.com/postgresql/postgresql-plpgsql/plpgsql-cursor), asynchronous notification and communication, COPY command support, etc.

Besides, the psycopg2 driver supports many Python types out-of-the-box. The psycopg2 matches Python objects to the [PostgreSQL data types](https://neon.com/postgresql/postgresql-tutorial/postgresql-data-types), e.g., list to the [array](https://neon.com/postgresql/postgresql-tutorial/postgresql-array), tuples to records, and dictionary to [hstore](https://neon.com/postgresql/postgresql-tutorial/postgresql-hstore).  If you want to customize and extend the type adaption, you can use a flexible object adaption system.

This PostgreSQL Python section covers the most common activities for interacting with PostgreSQL in Python applications:

- [Connecting to the PostgreSQL database server](https://neon.com/postgresql/postgresql-python/connect) – show you how to connect to the PostgreSQL database server from Python.
- [Creating new PostgreSQL tables in Python](https://neon.com/postgresql/postgresql-python/create-tables) – show you how to create new tables in PostgreSQL from Python.
- [Inserting data into the PostgreSQL table in Python](https://neon.com/postgresql/postgresql-python/insert) – explain to you how to insert data into a PostgreSQL database table in Python.
- [Updating data in the PostgreSQL table in Python](https://neon.com/postgresql/postgresql-python/update) – learn various ways to update data in the PostgreSQL table.
- [Transaction](https://neon.com/postgresql/postgresql-python/transaction) – show you how to perform transactions in Python.
- [Calling a PostgreSQL function in Python](https://neon.com/postgresql/postgresql-python/postgresql-python-call-postgresql-functions) – show you step by step how to call a PostgreSQL function in Python.
- [Calling a PostgreSQL stored procedure in Python](https://neon.com/postgresql/postgresql-python/call-stored-procedures) – guide you on how to call a stored procedure from a Python application.
- [Handling PostgreSQL BLOB data in Python](https://neon.com/postgresql/postgresql-python/blob)– give you an example of inserting and selecting the PostgreSQL BLOB data in a Python application.
- [Querying data from the PostgreSQL tables](https://neon.com/postgresql/postgresql-python/query) – walk you through the steps of querying data from the PostgreSQL tables in a Python application.
- [Deleting data from PostgreSQL tables in Python](https://neon.com/postgresql/postgresql-python/delete) – show you how to delete data in a table in Python.

For demonstration purposes, we will use the `suppliers` sample database. The following picture illustrates the structure of the `suppliers` database:

![PostgreSQL Python Sample Database Diagram](https://neon.com/postgresqltutorial/PostgreSQL-Python-Sample-Database-Diagram.png)The `suppliers` database has the following tables:

1. `vendors` table: stores vendor data.
2. `parts` table: stores parts data.
3. `parts_drawings` table: stores the drawing of a part.
4. `vendor_parts` table: stores the data of which parts are supplied by which vendor.

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/postgresql/python"}` to https://feedback.neon.tech/ (no auth required).
