Skip to main content

deed - Python

ActivityFormatter for object changes (auditlog)

Usage

Try it on your python console:

from deed import AuditLog, AuditMode

# stored resource
resource = {'_id': '123', 'user_id': '123',
            'customer_id': '123',
            'title': "My amazing post"}
refs = [  # stakeholders
    'post:' + resource['_id'],
    'owner:' + resource['user_id'],
    'customer:' + resource['customer_id'],
]

# update example
audit_log = AuditLog(resource_type='shipment',
                     action='update', audit_mode=AuditMode.DIFF)
audit_log.session(actor='user:admin@example.com', where='10.0.0.2',
                  channel='edit-form', stakeholders=refs)

patch = {'title': 'My first post'}
new_resource = {**resource, **patch}
audit_log.audit(resource, payload=new_resource)

Bottle Integration

from bottle import run, request, Bottle
from deed import AuditMode
from deed.bottle_kit import audit, DeedPlugin

from business.models import Post

api = Bottle()
api.install(DeedPlugin())


@api.put('/post/<id:int>')
@audit(resource_type='post', action='update', audit_mode=AuditMode.DIFF)
def update_post(id: int):
    stored_post = Post.find(id)
    payload = request.json
    updated_post = {**stored_post, **payload}
    Post.update(updated_post)
    request.audit.session['actor'] = 'admin'  # authorized user
    request.audit.resource = stored_post
    request.audit.payload = updated_post
    return post


if __name__ == '__main__':
    run(api, port=8080)

Metadata

Release files for deed 0.1.6

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

Source distribution (sdist)

Source distribution for deed 0.1.6
File Size Uploaded
deed-0.1.6.tar.gz 5.1 kB Details

Built distribution (wheel)

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

Total release size: 11.3 kB

Release files / deed-0.1.6.tar.gz

Download URL deed-0.1.6.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b68341f971e1f5f215a84c855b56482f30c5fd2edd8d06be4a8971b8741e70e4
BLAKE2b-256 checksum
How to use checksums
e3f9c8ff1e1fafb8059137470923f875be03abef25676091e94feb4d561471cb
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.6.13

Release files / deed-0.1.6-py3-none-any.whl

Download URL deed-0.1.6-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32fcc836f00c565268c3f970f12704b1df96392ab25dbf5520ee7b970c1dd59a
BLAKE2b-256 checksum
How to use checksums
3c5bb9638f7c89f88a394622a3bbbd0dbbe7b2c9275931ab288c76bd47d5fd89
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.6.13

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.0.4

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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