Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jP6gY-0003xD-Om for pgsql-interfaces@arkaria.postgresql.org; Thu, 16 Apr 2020 15:44:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jP6gX-0005Uf-KN for pgsql-interfaces@arkaria.postgresql.org; Thu, 16 Apr 2020 15:44:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jP6gX-0005UY-9U for pgsql-interfaces@lists.postgresql.org; Thu, 16 Apr 2020 15:44:13 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jP6gU-0007P9-60 for pgsql-interfaces@lists.postgresql.org; Thu, 16 Apr 2020 15:44:11 +0000 Received: by mail-qt1-x841.google.com with SMTP id q17so16452815qtp.4 for ; Thu, 16 Apr 2020 08:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tlocke-org-uk.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=t2+cMB+rqIgAHA+jz5kEOKi2tUgEw0jwSOJwmaBnDck=; b=o0NV7BRr6LnEkv+f0u7/ZOLJT3PGd04BmpUHHpVYk8za3MoNB80p1qyoTaEo5QSo7z MRZ7BaolQvuKS7egXydGtqcU6Hain0jDt/OBj8g/Rn0cyKSyeiIkryq9KTZkhxKz/8rJ CEUTTQAxJ401xS9yCX0YYTCYzOLB8K/hhXcMaUJ8IJRGnHYAdncfp9ilPAxliqFkJVss c61alll8+ldd5wShfczTUoDTgvSx5DC3xnZrVi6SnS4CPm9oOjC6Ys+Yk3piwtYXZCL/ vn6XXXr74uaPuA94FNPo+IymFzrn+lSRX9EplNu6F3Sjksf2MDD1jFuqiIAov3zT2KLV s+Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=t2+cMB+rqIgAHA+jz5kEOKi2tUgEw0jwSOJwmaBnDck=; b=nC2KsZJNubfLuNX9LAd/uLdL+BW8SHmCk1MHwPMXUxLfSezOslE0bfOCL/KC2YVMBs raSnawybRPfi24kSzvOrixETerwOYQgau1ysmcmCVnc9pzr5Zi8wxemZk/88vYovmehi SLwywrYbTpZazYtd1Z9c3JxuB7iD0oaHM87lyVYDCImcv/80fohTY1WIXdX94gsKVeQM VvteJ5dYqATreYMzf8JAZjk21Gm71EsJ8vzOSxjRRfeTaHG6QMYo+IzFjWmZ/cFSFxvb hcGE1MGqqDMepSJIKbO4/4WKGGEpAotxRjnxK3y/Wlswxwz2oa2PucOtvyh35CaJs8Gz hiqA== X-Gm-Message-State: AGi0PuaWfnFuICGzvOIfxmXPZEfjXrJ4VlRlNX+76eIzDA/nUb4QR8nE QloOaydXZDAxSGCs3/Q30YtOUN7yGOJfD6ZMe7F+oRKkv94= X-Google-Smtp-Source: APiQypL8mz2SNg6L0snmzS98Cv3XglK/Ln0OZjPrvjz4I+NaUvZEM/7HJVB1ZZIDkqsr6CIzzfym8Np+gOLhdhqkqyM= X-Received: by 2002:ac8:7549:: with SMTP id b9mr27543358qtr.390.1587051848590; Thu, 16 Apr 2020 08:44:08 -0700 (PDT) MIME-Version: 1.0 From: Tony Locke Date: Thu, 16 Apr 2020 16:43:57 +0100 Message-ID: Subject: New run() method to simplify things in pg8000 To: pgsql-interfaces@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi all, pg8000 is a pure-Python driver for Postgres https://github.com/tlocke/pg8000 and in the latest version of pg8000 I've added a run() method to the connection that lets you run SQL statements without needing a cursor. The idea is to make things a bit simpler for people. There are a few other differences too. The run() method always uses the 'named' parameter style, and the parameters are always provided as keyword arguments. Here's an example: >>> import pg8000 >>> >>> # Connect to the database with user name postgres >>> >>> con = pg8000.connect("postgres", password="C.P.Snow") >>> >>> # Create a temporary table >>> >>> con.run("CREATE TEMPORARY TABLE book (id SERIAL, title TEXT)") () >>> >>> # Populate the table >>> >>> for title in ("Ender's Game", "The Magus"): ... con.run("INSERT INTO book (title) VALUES (:title)", title=title) () () >>> >>> # Print all the rows in the table >>> >>> for row in con.run("SELECT * FROM book WHERE id > :min_id", min_id=0): ... print(row) [1, "Ender's Game"] [2, 'The Magus'] >>> >>> # Commit the transaction >>> >>> con.commit() I'd be interested in any thoughts / feedback if you have any. Thanks, Tony.