asyncpg

Code

import os
import asyncio
import asyncpg

async def query():
  connection = await asyncpg.connect(os.environ['DATABASE_URL'])
  result = await connection.fetch("SELECT $1::text AS greeting", "Hello world!")
  print(result)
  await connection.close()

asyncio.run(query())

Elephantshark transcript

listening ...
connected at t0 = 2025-10-08 22:40:37 +0200
client -> script: "\x00\x00\x00\x08\x04\xd2\x16\x2f" = SSLRequest
script -> client: "S" = SSL supported
TLSv1.3/TLS_AES_256_GCM_SHA384 connection established with client
  server name via SNI: localhost
client -> script: "\x00\x00\x00\x3e" = 62 bytes of startup message "\x00\x03\x00\x00" = protocol version
  "client_encoding\x00" = key "'utf-8'\x00" = value
  "user\x00" = key "frodo\x00" = value
  "database\x00" = key "postgres\x00" = value
  "\x00" = end
connecting to Postgres server: localhost
script -> server: "\x00\x00\x00\x08\x04\xd2\x16\x2f" = SSLRequest
server -> script: "S" = SSL supported
TLSv1.3/TLS_AES_256_GCM_SHA384 connection established with server
forwarding client startup message to server
script -> server: "\x00\x00\x00\x3e" = 62 bytes of startup message "\x00\x03\x00\x00" = protocol version
  "client_encoding\x00" = key "'utf-8'\x00" = value
  "user\x00" = key "frodo\x00" = value
  "database\x00" = key "postgres\x00" = value
  "\x00" = end
forwarding all later traffic
server -> client: "R" = Authentication "\x00\x00\x00\x2a" = 42 bytes "\x00\x00\x00\x0a" = AuthenticationSASL
  "SCRAM-SHA-256-PLUS\x00" = SASL mechanism
  "SCRAM-SHA-256\x00" = SASL mechanism
  "\x00" = end
^^ 43 bytes forwarded at +0.02s, 0 bytes left in buffer
client -> server: "p" = SASLInitialResponse "\x00\x00\x00\x43" = 67 bytes
  "SCRAM-SHA-256\x00" = selected mechanism
  "\x00\x00\x00\x2d" = 45 bytes follow
  "n,,n=frodo,r=Bjo3pSNSXEtf938BQBbie1NeYU1Q/wXY" = SCRAM client-first-message
^^ 68 bytes forwarded at +0.02s, 0 bytes left in buffer
server -> client: "R" = Authentication "\x00\x00\x00\x64" = 100 bytes "\x00\x00\x00\x0b" = AuthenticationSASLContinue
  "r=Bjo3pSNSXEtf938BQBbie1NeYU1Q/wXYV1iaivYS3sGIgBZMH7mSW/ri,s=ZPXsknNfrTfGBNripnqk4A==,i=4096" = SCRAM server-first-message
^^ 101 bytes forwarded at +0.03s, 0 bytes left in buffer
client -> server: "p" = SASLResponse "\x00\x00\x00\x74" = 116 bytes
  "c=biws,r=Bjo3pSNSXEtf938BQBbie1NeYU1Q/wXYV1iaivYS3sGIgBZMH7mSW/ri,p=X+HqCu1PNQ3XeaXBo3c62m8hBckW8BHZktkmkH2cLy8=" = SCRAM client-final-message
^^ 117 bytes forwarded at +0.04s, 0 bytes left in buffer
server -> client: "R" = Authentication "\x00\x00\x00\x36" = 54 bytes "\x00\x00\x00\x0c" = AuthenticationSASLFinal
  "v=K+hSZK4ExbzhLJRnxzGuda993zVtIOPmdxOPNor6HxA=" = SCRAM server-final-message
server -> client: "R" = Authentication "\x00\x00\x00\x08" = 8 bytes "\x00\x00\x00\x00" = AuthenticationOk
server -> client: "S" = ParameterStatus "\x00\x00\x00\x17" = 23 bytes "in_hot_standby\x00" = key "off\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "integer_datetimes\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x15" = 21 bytes "TimeZone\x00" = key "Etc/UTC\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x1b" = 27 bytes "IntervalStyle\x00" = key "postgres\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x20" = 32 bytes "search_path\x00" = key "\"$user\", public\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x14" = 20 bytes "is_superuser\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x16" = 22 bytes "application_name\x00" = key "\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x26" = 38 bytes "default_transaction_read_only\x00" = key "off\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x1a" = 26 bytes "scram_iterations\x00" = key "4096\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x17" = 23 bytes "DateStyle\x00" = key "ISO, MDY\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x23" = 35 bytes "standard_conforming_strings\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x20" = 32 bytes "session_authorization\x00" = key "frodo\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "client_encoding\x00" = key "UTF8\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x31" = 49 bytes "server_version\x00" = key "18.0 (Debian 18.0-1.pgdg13+3)\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "server_encoding\x00" = key "UTF8\x00" = value
server -> client: "K" = BackendKeyData "\x00\x00\x00\x0c" = 12 bytes "\x00\x00\x00\x5c" = process ID "\xd4\xfd\xea\x42" = secret key
server -> client: "Z" = ReadyForQuery "\x00\x00\x00\x05" = 5 bytes "I" = idle
^^ 521 bytes forwarded at +0.04s, 0 bytes left in buffer
client -> server: "P" = Parse "\x00\x00\x00\x35" = 53 bytes "__asyncpg_stmt_1__\x00" = destination prepared statement "SELECT $1::text AS greeting\x00" = SQL query "\x00\x00" = 0 parameter data types follow
client -> server: "D" = Describe "\x00\x00\x00\x18" = 24 bytes "S" = prepared statement "__asyncpg_stmt_1__\x00" = name of prepared statement
client -> server: "H" = Flush "\x00\x00\x00\x04" = 4 bytes
^^ 84 bytes forwarded at +0.06s, 0 bytes left in buffer
server -> client: "1" = ParseComplete "\x00\x00\x00\x04" = 4 bytes
server -> client: "t" = ParameterDescription "\x00\x00\x00\x0a" = 10 bytes "\x00\x01" = number of parameters "\x00\x00\x00\x19" = parameter type OID: 25
server -> client: "T" = RowDescription "\x00\x00\x00\x21" = 33 bytes "\x00\x01" = 1 columns follow
  "greeting\x00" = column name "\x00\x00\x00\x00" = table OID: 0 "\x00\x00" = table attrib no: 0
  "\x00\x00\x00\x19" = type OID: 25 "\xff\xff" = type length: -1 "\xff\xff\xff\xff" = type modifier: -1 "\x00\x00" = format: text
^^ 50 bytes forwarded at +0.06s, 0 bytes left in buffer
client -> server: "B" = Bind "\x00\x00\x00\x32" = 50 bytes "\x00" = destination portal "__asyncpg_stmt_1__\x00" = source prepared statement
  "\x00\x01" = 1 parameter format codes follow "\x00\x01" = format: binary
  "\x00\x01" = 1 parameter values follow "\x00\x00\x00\x0c" = 12 bytes follow "Hello world!" = parameter value
  "\x00\x01" = 1 result format codes follow "\x00\x01" = format: binary
client -> server: "E" = Execute "\x00\x00\x00\x09" = 9 bytes "\x00" = portal name "\x00\x00\x00\x00" = max rows: 0 = no limit
client -> server: "S" = Sync "\x00\x00\x00\x04" = 4 bytes
^^ 66 bytes forwarded at +0.06s, 0 bytes left in buffer
server -> client: "2" = BindComplete "\x00\x00\x00\x04" = 4 bytes
server -> client: "D" = DataRow "\x00\x00\x00\x16" = 22 bytes "\x00\x01" = 1 columns follow
  "\x00\x00\x00\x0c" = 12 bytes "Hello world!" = column value
server -> client: "C" = CommandComplete "\x00\x00\x00\x0d" = 13 bytes "SELECT 1\x00" = command tag
server -> client: "Z" = ReadyForQuery "\x00\x00\x00\x05" = 5 bytes "I" = idle
^^ 48 bytes forwarded at +0.06s, 0 bytes left in buffer
client -> server: "X" = Terminate "\x00\x00\x00\x04" = 4 bytes
^^ 5 bytes forwarded at +0.07s, 0 bytes left in buffer
server hung up
connection end

listening ...
connection end