# pyencrypt-pye
---
[](https://github.com/ZhaoQi99/pyencrypt-pye/actions/workflows/main.yml)
[](https://pypi.python.org/pypi/pyencrypt-pye)
[](https://pypi.python.org/pypi/pyencrypt-pye)
[](https://pypi.python.org/pypi/pyencrypt-pye)
[](https://github.com/ZhaoQi99/pyencrypt-pye/blob/main/LICENSE)

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
```bash
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](./examples) directory.
## Usage
```shell
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
```shell
~$ 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.
```python
import loader
from test import *
```
### Decrypt
```shell
~$ 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
```shell
~$ 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.
```shell
~$ 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
<details open>
<summary>Bash</summary>
Add this to ~/.bashrc:
```shell
eval "$(_PYENCRYPT_COMPLETE=bash_source pyencrypt)"
```
</details>
<details>
<summary>Zsh</summary>
Add this to ~/.zshrc:
```shell
eval "$(_PYENCRYPT_COMPLETE=zsh_source pyencrypt)"
```
</details>
<details>
<summary>Fish</summary>
Add this to ~/.config/fish/completions/foo-bar.fish:
```shell
eval (env _PYENCRYPT_COMPLETE=fish_source pyencrypt)
```
</details>
## Example
### Encrypt
```shell
~$ 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
```shell
~$ pyencrypt decrypt -k xxx test.pye
```
### Generate
```shell
~$ pyencrypt generate -k xxx
```
### License
```shell
~$ 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](FAQ.md) for frequently asked questions.
## Development
### Format Code
```shell
black pyencrypt
isort pyencrypt
```
## License
[GNU General Public License v3.0](https://github.com/ZhaoQi99/pyencrypt-pye/blob/main/LICENSE)
## Author
* Qi Zhao([zhaoqi99@outlook.com](mailto:zhaoqi99@outlook.com))
Raw data
{
"_id": null,
"home_page": "https://github.com/ZhaoQi99/pyencrypt-pye",
"name": "pyencrypt-pye",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.14,>=3.6",
"maintainer_email": null,
"keywords": "python-encrypt, import-hook",
"author": "Qi Zhao",
"author_email": "zhaoqi99@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/bb/44/497a79ba2fcff5ffd0d57efab9771ace35e46eeb260524d24766b0f6701a/pyencrypt-pye-0.5.0.tar.gz",
"platform": null,
"description": "# pyencrypt-pye\u00a0\n\n---\n[](https://github.com/ZhaoQi99/pyencrypt-pye/actions/workflows/main.yml)\n[](https://pypi.python.org/pypi/pyencrypt-pye)\n[](https://pypi.python.org/pypi/pyencrypt-pye)\u00a0\n[](https://pypi.python.org/pypi/pyencrypt-pye)\n[](https://github.com/ZhaoQi99/pyencrypt-pye/blob/main/LICENSE)\u00a0\n\u00a0\n\n\nencrypt python source code and import module dynamically.\n\n```\n _\n _ __ _ _ ___ _ __ ___ _ __ _ _ _ __ | |_\n | '_ \\| | | |/ _ \\ '_ \\ / __| '__| | | | '_ \\| __|\n | |_) | |_| | __/ | | | (__| | | |_| | |_) | |_\n | .__/ \\__, |\\___|_| |_|\\___|_| \\__, | .__/ \\__|\n |_| |___/ |___/|_|\n\n encrypt python source code and import dynamically.\n\n VERSION 0.5.0\n```\n## How to do\nhttps://github.com/ZhaoQi99/pyencrypt-pye/wiki#how-to-do\n\n## Install\n\n```bash\npip install pyencrypt-pye\n\u2728\ud83c\udf70\u2728\n```\nOr you can use `pip install git+https://github.com/ZhaoQi99/pyencrypt-pye.git` install latest version.\n\n## Examples\nView examples in the [examples](./examples) directory.\n\n## Usage\n\n```shell\nUsage: pyencrypt [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n --version Show the version and exit.\n -h, --help Show this message and exit.\n\nCommands:\n decrypt Decrypt encrypted pye file\n encrypt Encrypt your python code\n generate Generate loader file using specified key\n license Generate license file using specified key\n```\n\n### Encrypt\n\n```shell\n~$ pyencrypt encrypt -h\nUsage: pyencrypt encrypt [OPTIONS] PATHNAME\n\n Encrypt your python code\n\nOptions:\n -i, --in-place make changes to files in place\n -k, --key \ud83d\udd11 Your encryption key.If you don\u2018t specify\n key, pyencrypt will generate encryption key\n randomly. [env var: PYE_ENCRYPT_KEY]\n --without-loader Don't generate loader file\n --with-license Add license to encrypted file\n -m, --bind-mac 01:23:45:67:89:AB\n Bind mac address to encrypted file\n -4, --bind-ipv4 192.168.0.1 Bind ipv4 address to encrypted file\n -b, --before [%Y-%m-%dT%H:%M:%S %z|%Y-%m-%d %H:%M:%S|%Y-%m-%d]\n License is invalid before this date.\n -a, --after [%Y-%m-%dT%H:%M:%S %z|%Y-%m-%d %H:%M:%S|%Y-%m-%d]\n License is invalid after this date.\n -y, --yes Automatically answer yes for confirm\n questions.\n -h, --help Show this message and exit.\n```\n\n### Entry File\n\nIn your entry file, you must import `loader` firstly, and then you can import encrypted modules as usual.\n\n```python\nimport loader\nfrom test import *\n```\n\n### Decrypt\n\n```shell\n~$ pyencrypt decrypt -h\nUsage: pyencrypt decrypt [OPTIONS] PATHNAME\n\n Decrypt encrypted pye file\n\nOptions:\n -i, --in-place make changes to files in place\n -k, --key \ud83d\udd11 Your encryption key. [required]\n -h, --help Show this message and exit.\n```\n\n### Generate\n\n```shell\n~$ pyencrypt generate -h\nUsage: pyencrypt generate [OPTIONS]\n\n Generate loader file using specified key\n\nOptions:\n -k, --key \ud83d\udd11 Your encryption key. [required]\n -h, --help Show this message and exit.\n```\n\n### License\n\npyencrypt's loader will search for the license file in the following manner:\n\n1. `~/.licenses/license.lic`\u00a0file in your home directory.\n\n2. `licenses/license.lic` file in `loader` file's directory.\n\n3. `licenses/license.lic`\u00a0file in the current working directory.\n\n```shell\n~$ pyencrypt license -h\n Usage: pyencrypt license [OPTIONS]\n\n Generate license file using specified key\n\nOptions:\n -h, --help Show this message and exit.\n -k, --key \ud83d\udd11 Your encryption key. [required]\n -m, --bind-mac 01:23:45:67:89:AB\n Bind mac address to encrypted file\n -4, --bind-ipv4 192.168.0.1 Bind ipv4 address to encrypted file\n -b, --before [%Y-%m-%dT%H:%M:%S %z|%Y-%m-%d %H:%M:%S|%Y-%m-%d]\n License is invalid before this date.\n -a, --after [%Y-%m-%dT%H:%M:%S %z|%Y-%m-%d %H:%M:%S|%Y-%m-%d]\n License is invalid after this date.\n```\n\n### Shell Completion\n\n<details open>\n<summary>Bash</summary>\nAdd this to ~/.bashrc:\n\n```shell\neval \"$(_PYENCRYPT_COMPLETE=bash_source pyencrypt)\"\n```\n</details>\n\n<details>\n<summary>Zsh</summary>\nAdd this to ~/.zshrc:\n\n```shell\neval \"$(_PYENCRYPT_COMPLETE=zsh_source pyencrypt)\"\n```\n</details>\n\n<details>\n<summary>Fish</summary>\nAdd this to ~/.config/fish/completions/foo-bar.fish:\n\n```shell\neval (env _PYENCRYPT_COMPLETE=fish_source pyencrypt)\n```\n</details>\n\n## Example\n\n### Encrypt\n\n```shell\n~$ pyencrypt encrypt --in-place -y test.py\n~$ pyencrypt encrypt test/\n~$ pyencrypt encrypt test.py -y --with-license\\\n --before=\"2000-01-01T00:00:00 +0800\" --after=\"2030-01-01T00:00:00 +0800\"\\\n --bind-mac=\"AC:DE:48:00:11:22\" --bind-ipv4=\"192.168.0.1\"\n```\n\n### Decrypt\n\n```shell\n~$ pyencrypt decrypt -k xxx test.pye\n```\n\n### Generate\n\n```shell\n~$ pyencrypt generate -k xxx\n```\n\n### License\n\n```shell\n~$ pyencrypt license -k xxx\\\n --before=\"2000-01-01T00:00:00 +0800\" --after=\"2030-01-01T00:00:00 +0800\"\\\n --bind-mac=\"AC:DE:48:00:11:22\" --bind-ipv4=\"192.168.0.1\"\n```\n## FAQ\n\nSee [FAQ](FAQ.md) for frequently asked questions.\n\n## Development\n\n### Format Code\n\n```shell\nblack pyencrypt \nisort pyencrypt\n```\n\n## License\n\n[GNU General Public License v3.0](https://github.com/ZhaoQi99/pyencrypt-pye/blob/main/LICENSE)\n\n## Author\n\n* Qi Zhao([zhaoqi99@outlook.com](mailto:zhaoqi99@outlook.com))\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Encrypt python source code and import module dynamically.",
"version": "0.5.0",
"project_urls": {
"Changelog": "https://github.com/ZhaoQi99/pyencrypt-pye/releases",
"Homepage": "https://github.com/ZhaoQi99/pyencrypt-pye",
"Issue Tracker": "https://github.com/ZhaoQi99/pyencrypt-pye/issues",
"Source": "https://github.com/ZhaoQi99/pyencrypt-pye"
},
"split_keywords": [
"python-encrypt",
" import-hook"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d28e32d9d829de06f52ebd0fe3b0141aeccbd7cc454a5353c387af4a23873059",
"md5": "8f5c88c3180c088f31de23e1a88c88a3",
"sha256": "d4b810340d49a2714f094a11e89aa1e4aac3b71ed32fc4c2ff363bd5e40ce352"
},
"downloads": -1,
"filename": "pyencrypt_pye-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8f5c88c3180c088f31de23e1a88c88a3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.14,>=3.6",
"size": 42289,
"upload_time": "2025-07-29T09:52:28",
"upload_time_iso_8601": "2025-07-29T09:52:28.836179Z",
"url": "https://files.pythonhosted.org/packages/d2/8e/32d9d829de06f52ebd0fe3b0141aeccbd7cc454a5353c387af4a23873059/pyencrypt_pye-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bb44497a79ba2fcff5ffd0d57efab9771ace35e46eeb260524d24766b0f6701a",
"md5": "6a0722ad656dceed9e14670635e0a10e",
"sha256": "b1d6f44e6734366dc070170ec796e49eb833ec1b42864a70a750127f6f67223c"
},
"downloads": -1,
"filename": "pyencrypt-pye-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "6a0722ad656dceed9e14670635e0a10e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.14,>=3.6",
"size": 41677,
"upload_time": "2025-07-29T09:52:30",
"upload_time_iso_8601": "2025-07-29T09:52:30.208175Z",
"url": "https://files.pythonhosted.org/packages/bb/44/497a79ba2fcff5ffd0d57efab9771ace35e46eeb260524d24766b0f6701a/pyencrypt-pye-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-29 09:52:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ZhaoQi99",
"github_project": "pyencrypt-pye",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyencrypt-pye"
}