Download Python source code from here -> [login to view URL]
Integrate a custom script (say [login to view URL]) into the above downloaded source code
Compile the source code and create python binary.
When you run python in command line, the [login to view URL] script must be executed first. If it passes, then continue with the usual python execution. If it fails, then exit with a custom message (for e.g. something like: "Condition failed. Exiting") and do not run python.
Here's an example:
Python 3.10.6 (default, Apr 11 2022, 06:30:15)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10.0.1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
Condition failed. Exiting!