Postfix queue

Lately I wrote in python postfix policy service that can do something for
me what I want.
Now I am thinking about next service butI don't know maybe it is not

That is my question:

There is posssible write some service similar to eg.

check_policy_service unix:private/policy-spf

It is possible to write some policy service that will be working with
postfix queue ?

I would like have policy service that will be able to write do data base
some information eg. when exactly message was sent, message ID, DSN if
soemthing goes wrong. That means it should be working with Postfix queue.

But policy services can be configured with smtpd_sender_restrictions and
It 's possible configure some policy service with postfix queue ?