Skip to content

Viicos/sourceprotected

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sourceprotected

Encrypt Python source files and decrypt them on the fly during runtime.

Python versions Code style: Black Ruff

Usage

Installation

Using pip:

pip install sourceprotected

Encrypting the source files

sourceprotected path/to/src(.py)
Using key: fHC79...
Using encryption time: 1694...

Decrypt during runtime

With sourceprotected installed in your current environment, you can run/import encrypted files/modules as long as the SOURCEPROTECTED_KEY environment variable is set:

encrypted.py:

# -*- coding: sourceprotected -*-

-----BEGIN SOURCEPROTECTED FILE-----
gAAAAABk-eJaJarzMWy70GTRkRi6kjaD-zJy
-fHX_0G5VHTZjEKxJUvFhVWfWpX_j3LydmJo
pn7YrAj5CSqqPWgxUY_dSk5ELA==
-----END SOURCEPROTECTED FILE-----

main.py:

import encrypted  # Will decrypt encrypted.py on the fly.

Finally:

SOURCEPROTECTED_KEY=Bk92p... python -B main.py

How does it work?

sourceprotected uses a custom codec that will decrypt the file content using the SOURCEPROTECTED_KEY environment variable.

This codec is registered on startup by using a .pth file.

Credits goes to https://github.com/asottile-archive/future-fstrings for the implementation idea.

About

Encrypt Python source files and decrypt them on the fly during runtime.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages