I was surprised in not seeing pyconcrete in any answer. Maybe because it's newer than the question?
It could be exactly what you need(ed).
Instead of obfuscating the code, it encrypts it and decrypts at load time.
From pypi page:
Protect python script work flow
- your_script.py
import pyconcrete
- pyconcrete will hook import module
- when your script do import
MODULE
,
pyconcrete import hook will try to find MODULE.pye
first and then
decrypt MODULE.pye
via _pyconcrete.pyd
and execute decrypted data (as
.pyc content)
- encrypt & decrypt secret key record in
_pyconcrete.pyd
(like DLL or SO) the secret key would be hide in binary code, can’t
see it directly in HEX view