<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/postgresql-adapter-for-python-rkeibhpus" -->

---
title: PostgreSQL adapter for Python | daily.dev
description: Psycopg 2.5, the popular PostgreSQL adapter for Python, adds a JSON adapter for exchanging unstructured data, Range type adapters for PostgreSQL 9.2 range...
canonical: https://daily.dev/posts/postgresql-adapter-for-python-rkeibhpus
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: PostgreSQL adapter for Python | daily.dev
og:description: Psycopg 2.5, the popular PostgreSQL adapter for Python, adds a JSON adapter for exchanging unstructured data, Range type adapters for PostgreSQL 9.2 range...
og:url: https://daily.dev/posts/postgresql-adapter-for-python-rkeibhpus
og:image: https://api.daily.dev/og/posts/RKEIbhpus.png
og:image:alt: PostgreSQL adapter for Python
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# PostgreSQL adapter for Python

**[Psycopg](https://daily.dev/sources/psycopg)** · 3 min read · 0 upvotes · 0 comments

## Summary

Psycopg 2.5, the popular PostgreSQL adapter for Python, adds a JSON adapter for exchanging unstructured data, Range type adapters for PostgreSQL 9.2 range types, and support for using connections and cursors as context managers per a recent DBAPI extension. Other additions include a Diagnostics object for extended database error info, a cursor_factory attribute, backward scrollable cursors, and custom casting of composite types. Python 3.3 support was added while Python 2.4 support was dropped, and the Zope adapter was moved out to its own project.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.psycopg.org/articles/2013/04/07/psycopg-25-released>

## Questions this post answers

### How do I insert JSON data into PostgreSQL using psycopg2?

Use the psycopg2.extras.Json adapter to wrap a Python object before passing it as a query parameter, for example cur.execute("insert into mytable (jsondata) values (%s)", [Json({'a': 100})]). Alternatively, register Json globally with psycopg2.extensions.register_adapter(dict, Json) so plain dictionaries are automatically serialized to JSON on every query. This works with PostgreSQL 9.2's native json type, older JSON extension modules, or plain text.

_Developers wiring JSON into PostgreSQL from Python can track adapter changes like this on daily.dev._

### How do I work with PostgreSQL range types in Python using psycopg2?

Psycopg2 2.5 returns PostgreSQL range values (like int4range or daterange) as Range objects with .lower, .upper, and .upper_inc properties for inspecting bounds. Built-in range types work out of the box, and register_range() lets you handle user-defined range types. Range objects like DateRange can also be passed directly as query parameters, e.g. cur.execute("select * from events where %s @> date", [r]).

_Anyone modeling date or numeric ranges in PostgreSQL can follow adapter updates on daily.dev._

### Can I use psycopg2 connections and cursors as context managers with with statements?

Yes, psycopg2 2.5 supports using connections and cursors as context managers following a DBAPI extension: with psycopg2.connect(DSN) as conn: with conn.cursor() as curs: curs.execute(SQL). Exiting the cursor block closes the cursor; exiting the connection block commits the transaction on success or rolls it back on exception, and the connection itself stays open and reusable afterward.

_Python developers adopting cleaner transaction handling can follow driver changes like this on daily.dev._

## Similar posts on daily.dev

- [PostgreSQL adapter for Python](https://daily.dev/posts/postgresql-adapter-for-python-7mss4n5wr) · Psycopg · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/postgresql-adapter-for-python-rkeibhpus)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"PostgreSQL adapter for Python","url":"https://daily.dev/posts/postgresql-adapter-for-python-rkeibhpus","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/postgresql-adapter-for-python-rkeibhpus"},"datePublished":"2026-08-23T12:21:54.865Z","dateModified":"2026-08-23T12:40:23.228Z","description":"Psycopg 2.5, the popular PostgreSQL adapter for Python, adds a JSON adapter for exchanging unstructured data, Range type adapters for PostgreSQL 9.2 range...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b0cbd2ac8948f96ab39fa6a90db7464f?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b0cbd2ac8948f96ab39fa6a90db7464f?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Psycopg","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Psycopg","logo":"https://media.daily.dev/image/upload/s--5N-KNNWk--/f_auto,q_auto/v1787487485/logos/psycopg?_a=BAMAMicg0","url":"https://daily.dev/sources/psycopg"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/postgresql-adapter-for-python-rkeibhpus","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,postgresql","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Psycopg","item":"https://daily.dev/sources/psycopg"},{"@type":"ListItem","position":3,"name":"PostgreSQL adapter for Python"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/postgresql-adapter-for-python-rkeibhpus#faq","mainEntity":[{"@type":"Question","name":"How do I insert JSON data into PostgreSQL using psycopg2?","acceptedAnswer":{"@type":"Answer","text":"Use the psycopg2.extras.Json adapter to wrap a Python object before passing it as a query parameter, for example cur.execute(\"insert into mytable (jsondata) values (%s)\", [Json({'a': 100})]). Alternatively, register Json globally with psycopg2.extensions.register_adapter(dict, Json) so plain dictionaries are automatically serialized to JSON on every query. This works with PostgreSQL 9.2's native json type, older JSON extension modules, or plain text. Developers wiring JSON into PostgreSQL from Python can track adapter changes like this on daily.dev."}},{"@type":"Question","name":"How do I work with PostgreSQL range types in Python using psycopg2?","acceptedAnswer":{"@type":"Answer","text":"Psycopg2 2.5 returns PostgreSQL range values (like int4range or daterange) as Range objects with .lower, .upper, and .upper_inc properties for inspecting bounds. Built-in range types work out of the box, and register_range() lets you handle user-defined range types. Range objects like DateRange can also be passed directly as query parameters, e.g. cur.execute(\"select * from events where %s @> date\", [r]). Anyone modeling date or numeric ranges in PostgreSQL can follow adapter updates on daily.dev."}},{"@type":"Question","name":"Can I use psycopg2 connections and cursors as context managers with with statements?","acceptedAnswer":{"@type":"Answer","text":"Yes, psycopg2 2.5 supports using connections and cursors as context managers following a DBAPI extension: with psycopg2.connect(DSN) as conn: with conn.cursor() as curs: curs.execute(SQL). Exiting the cursor block closes the cursor; exiting the connection block commits the transaction on success or rolls it back on exception, and the connection itself stays open and reusable afterward. Python developers adopting cleaner transaction handling can follow driver changes like this on daily.dev."}}]}
```

