Overriding default adapters in psycopg

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: psycopg(at)lists(dot)postgresql(dot)org
Subject: Overriding default adapters in psycopg
Date: 2025-11-16 16:56:07
Message-ID: FA57033D-66AE-42E9-8C5E-968CF69DB893@thebuild.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: psycopg

Hi!

I am attempting to override the default adapters for JSON and JSONB in psycopg (3), but I am not quite sure how to go about it (I'm testing using orjson for serialization and deserialization). This doesn't appear to work:

> class CyanJSONBLoader(Loader):
> def load(self, data):
> return orjson.loads(data)
>
> psycopg.adapters.register_loader("jsonb", CyanJSONBLoader)
>
> class CyanJSONBDumper(Dumper):
> def dump(self, obj):
> return orjson.dumps(obj)
>
> psycopg.adapters.register_dumper("jsonb", CyanJSONBDumper)
>

The calls work, but the dump/load functions are never called.

Thanks!

Responses

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2025-11-16 17:25:42 Re: Overriding default adapters in psycopg
Previous Message Daniele Varrazzo 2025-09-09 07:52:47 Psycopg 3.3.0.dev1 released - with Template Strings support!