The following can be imported from
Given a string
querycontaining a MySQL query, returns a ‘fingerprint’ of the query from the Percona
pt-fingerprinttool (docs). You must therefore have
>>> pt_fingerprint("SELECT a, b FROM myapp_author WHERE id = 55") 'select a, b from myapp_author where id = ?' >>> pt_fingerprint("SELECT SLEEP(123)") 'select sleep(?)' >>> pt_fingerprint("release savepoint `ax123`") 'release savepoint `a?`'
This is a complex subprocess wrapper that is suitable for processing many queries serially - it opens
pt-fingerprintin a background thread, which accepts input line-by-line, and shuts it down after 60 seconds of not being used. It is therefore suitable for use one-query-at-a-time, even when batch processing hundreds of queries.
Because this uses Python’s
ptylibrary, it only works on Unix.