Skip to main content

SQLRecorder

This package serves as a Python Wrapper for use in recording the success or failure of any functions to a SQL table, along with any respective arguments or keyword arguments.

As of 2021-05-31 this package has only been tested with Microsoft SQL Server utilising pyodbc with SQL Server Native Client 11.0 and windows authentication (trusted_connection=yes).

Instructions

Install the package using pip install sqlrecorder
In your application, from sqlrecorder import SQLRecorderWrapper
Set up your config variables:

# instantiate SQLoggerOne as a copy of SQLRecorderWrapper so multiple configs are possible for the one application
SQLoggerOne = SQLRecorderWrapper
# what to do in the event the wrapped function throws an error
SQLoggerOne.config['ON_FAIL'] = 'pass'
# connection string
SQLoggerOne.config['CONNECTION_STRING'] = 'mssql+pyodbc://@DESKTOP-8TLT5OK\\SQLEXPRESS/Test?driver=SQL+Server+Native+Client+11.0?trusted_connection=yes'
# table name which the logs are written to
SQLoggerOne.config['TABLE_NAME'] = 'py_errorlog'

Config:

ON_FAIL
str: 'pass', passes when the wrapped function throws an error
str: 'return', returns the function and associated args and kwargs when the wrapped function throws an error
str: 'exit', returns sys.exit when the wrapped function throws an error

CONNECTION_STRING
str The connection string used to connect with the database instance. See: SQL Alchemy documentation

TABLE_NAME
str The table name to be created in SQL.

Sample Success

from sqlrecorder import SQLRecorderWrapper

SQLoggerOne = SQLRecorderWrapper
SQLoggerOne.config['ON_FAIL'] = 'pass'
SQLoggerOne.config['CONNECTION_STRING'] = 'mssql+pyodbc://srvr/db?driver=driver?trusted_connection=yes'
SQLoggerOne.config['TABLE_NAME'] = 'py_func_log'

@SQLoggerOne
def add_func(a,b):
    return a+b

add_func(2, 2)

Which will send to SQL:

Table upon a successful, wrapped function call

Sample Errors

Assuming the above code but with the following two calls of add_func

add_func(2, 2, 3) # invalid, third argument

add_func(2, 2, invalid_kwarg=1) # invalid keyword argument

Would update the existing table to:

Table updated when two errors are called from the same function

TODO:

  1. Return NULL/None when len(kwargs) == 0

Release files for sqlrecorder 1.0

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

Source distribution (sdist)

Source distribution for sqlrecorder 1.0
File Size Uploaded
sqlrecorder-1.0.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlrecorder 1.0
File Interpreter ABI Platform
sqlrecorder-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / sqlrecorder-1.0.tar.gz

Download URL sqlrecorder-1.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2fa748213e00e7e63adbcaeedd2618934fa9e8480de4dfb6c6097b32fcad5f4a
BLAKE2b-256 checksum
How to use checksums
3499e3f5acdbd18243eae55e0492889b7067827e4e958afa2f0ee61bc6e69317
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Release files / sqlrecorder-1.0-py3-none-any.whl

Download URL sqlrecorder-1.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc0b1f3be1450afb348e8e0e5dd6b5720da5171d61ea88b41a530d9af1adeb8a
BLAKE2b-256 checksum
How to use checksums
76886b8db71ef75dc149c50f3c28c934619bb2060f194c89eb9ec8eab9bb9268
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Release history Release notifications | RSS feed

This release

1.0 This release

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