Skip to main content

Encrypt python source code and import module dynamically.

Project description

pyencrypt-pye 


Python package Python version PyPI package  PyPI download GitHub  GitHub last commit (by committer) 

encrypt python source code and import module dynamically.

                                                      _
         _ __  _   _  ___ _ __   ___ _ __ _   _ _ __ | |_
        | '_ \| | | |/ _ \ '_ \ / __| '__| | | | '_ \| __|
        | |_) | |_| |  __/ | | | (__| |  | |_| | |_) | |_
        | .__/ \__, |\___|_| |_|\___|_|   \__, | .__/ \__|
        |_|    |___/                      |___/|_|

        encrypt python source code and import dynamically.

                    VERSION 0.5.0

How to do

https://github.com/ZhaoQi99/pyencrypt-pye/wiki#how-to-do

Install

pip install pyencrypt-pye
✨🍰✨

Or you can use pip install git+https://github.com/ZhaoQi99/pyencrypt-pye.git install latest version.

Examples

View examples in the examples directory.

Usage

Usage: pyencrypt [OPTIONS] COMMAND [ARGS]...

Options:
  --version   Show the version and exit.
  -h, --help  Show this message and exit.

Commands:
  decrypt   Decrypt encrypted pye file
  encrypt   Encrypt your python code
  generate  Generate loader file using specified key
  license   Generate license file using specified key

Encrypt

~$ pyencrypt encrypt -h
Usage: pyencrypt encrypt [OPTIONS] PATHNAME

  Encrypt your python code

Options:
  -i, --in-place                  make changes to files in place
  -k, --key 🔑                     Your encryption key.If you don‘t specify
                                  key, pyencrypt will generate encryption key
                                  randomly.  [env var: PYE_ENCRYPT_KEY]
  --without-loader                Don't generate loader file
  --with-license                  Add license to encrypted file
  -m, --bind-mac 01:23:45:67:89:AB
                                  Bind mac address to encrypted file
  -4, --bind-ipv4 192.168.0.1     Bind ipv4 address to encrypted file
  -b, --before [%Y-%m-%dT%H:%M:%S %z|%Y-%m-%d %H:%M:%S|%Y-%m-%d]
                                  License is invalid before this date.
  -a, --after [%Y-%m-%dT%H:%M:%S %z|%Y-%m-%d %H:%M:%S|%Y-%m-%d]
                                  License is invalid after this date.
  -y, --yes                       Automatically answer yes for confirm
                                  questions.
  -h, --help                      Show this message and exit.

Entry File

In your entry file, you must import loader firstly, and then you can import encrypted modules as usual.

import loader
from test import *

Decrypt

~$ pyencrypt decrypt -h
Usage: pyencrypt decrypt [OPTIONS] PATHNAME

  Decrypt encrypted pye file

Options:
  -i, --in-place  make changes to files in place
  -k, --key 🔑     Your encryption key.  [required]
  -h, --help      Show this message and exit.

Generate

~$ pyencrypt generate -h
Usage: pyencrypt generate [OPTIONS]

  Generate loader file using specified key

Options:
  -k, --key 🔑  Your encryption key.  [required]
  -h, --help   Show this message and exit.

License

pyencrypt's loader will search for the license file in the following manner:

  1. ~/.licenses/license.lic file in your home directory.

  2. licenses/license.lic file in loader file's directory.

  3. licenses/license.lic file in the current working directory.

~$ pyencrypt license -h
   Usage: pyencrypt license [OPTIONS]

   Generate license file  using specified key

Options:
  -h, --help                      Show this message and exit.
  -k, --key 🔑     Your encryption key.  [required]
  -m, --bind-mac 01:23:45:67:89:AB
                                  Bind mac address to encrypted file
  -4, --bind-ipv4 192.168.0.1     Bind ipv4 address to encrypted file
  -b, --before [%Y-%m-%dT%H:%M:%S %z|%Y-%m-%d %H:%M:%S|%Y-%m-%d]
                                  License is invalid before this date.
  -a, --after [%Y-%m-%dT%H:%M:%S %z|%Y-%m-%d %H:%M:%S|%Y-%m-%d]
                                  License is invalid after this date.

Shell Completion

Bash Add this to ~/.bashrc:
eval "$(_PYENCRYPT_COMPLETE=bash_source pyencrypt)"
Zsh Add this to ~/.zshrc:
eval "$(_PYENCRYPT_COMPLETE=zsh_source pyencrypt)"
Fish Add this to ~/.config/fish/completions/foo-bar.fish:
eval (env _PYENCRYPT_COMPLETE=fish_source pyencrypt)

Example

Encrypt

~$ pyencrypt encrypt --in-place  -y test.py
~$ pyencrypt encrypt test/
~$ pyencrypt encrypt test.py -y --with-license\
    --before="2000-01-01T00:00:00 +0800" --after="2030-01-01T00:00:00 +0800"\
    --bind-mac="AC:DE:48:00:11:22" --bind-ipv4="192.168.0.1"

Decrypt

~$ pyencrypt decrypt -k xxx test.pye

Generate

~$ pyencrypt generate -k xxx

License

~$ pyencrypt license -k xxx\
    --before="2000-01-01T00:00:00 +0800" --after="2030-01-01T00:00:00 +0800"\
    --bind-mac="AC:DE:48:00:11:22" --bind-ipv4="192.168.0.1"

FAQ

See FAQ for frequently asked questions.

Development

Format Code

black pyencrypt 
isort pyencrypt

License

GNU General Public License v3.0

Author

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyencrypt-pye-0.5.0.tar.gz (41.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyencrypt_pye-0.5.0-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

Details for the file pyencrypt-pye-0.5.0.tar.gz.

File metadata

  • Download URL: pyencrypt-pye-0.5.0.tar.gz
  • Upload date:
  • Size: 41.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.10 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for pyencrypt-pye-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b1d6f44e6734366dc070170ec796e49eb833ec1b42864a70a750127f6f67223c
MD5 6a0722ad656dceed9e14670635e0a10e
BLAKE2b-256 bb44497a79ba2fcff5ffd0d57efab9771ace35e46eeb260524d24766b0f6701a

See more details on using hashes here.

File details

Details for the file pyencrypt_pye-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pyencrypt_pye-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 42.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.10 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for pyencrypt_pye-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4b810340d49a2714f094a11e89aa1e4aac3b71ed32fc4c2ff363bd5e40ce352
MD5 8f5c88c3180c088f31de23e1a88c88a3
BLAKE2b-256 d28e32d9d829de06f52ebd0fe3b0141aeccbd7cc454a5353c387af4a23873059

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page