Skip to main content

PyPI - Python Version

Formal sqlcommenter

Formal sqlcommenter is a plugin that enables your ORMs to augment SQL statement before execution, with a comment containing the end-user id of a request. Sqlcommenter is typically useful for back-office application that needs to implement role access management.

Local Install

pip3 install --user formal-sqlcommenter

Usage

Psycopg2

Use the provided cursor factory to generate database cursors. All queries executed with such cursors will have the SQL comment prepended to them.

import psycopg2
from formal.sqlcommenter.psycopg2.extension import CommenterCursorFactory

cursor_factory = CommenterCursorFactory()
conn = psycopg2.connect(..., cursor_factory=cursor_factory)
cursor = conn.cursor()
cursor.execute('SELECT * from ...', '1234') # comment will be added before execution

which will produce a backend log such as when viewed on Postgresql

2019-05-28 02:33:25.287 PDT [57302] LOG:  statement: /*formal_role_id:1234*/ SELECT * FROM
polls_question 

Django

Add the provided Django middleware to your Django project's settings. All database queries executed by authenticated users within the standard request→response cycle will have a SQL comment prepended to them. The comment will inform Formal systems that the querying user has the External ID with a value of request.user.email, or if that does not exist, request.user.id.

MIDDLEWARE = [
+  'formal.sqlcommenter.django.databaseInstrumentation.FormalSqlCommenter',
  ...
]

Metadata

Release files for formal-sqlcommenter 1.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for formal-sqlcommenter 1.0.8
File Size Uploaded
formal-sqlcommenter-1.0.8.tar.gz 4.0 kB Details

Release files / formal-sqlcommenter-1.0.8.tar.gz

Download URL formal-sqlcommenter-1.0.8.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ad4108154194cbc13cbe79fa92fe2b53ac60633251e7d53c0751188e607b1632
BLAKE2b-256 checksum
How to use checksums
eaa1488f8b17ffa43b51a26c2715426b654e9e1d8e75ebf047225392fdac3a84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.0.8 This release

1 release file

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page