Skip to main content

package-obfuscator

Disclaimer

This package was developed as part of the SocialNetworkHarvester by the Freezingdata GmbH. We found the obfuscation of packages to be essential for our work so we developed this package. The package will be maintained as long as we need the functionality for our own software. We do not and cannot guarantee long-term maintenance, nor can be guarantee support in issues. We will nevertheless try to answer all incoming questions in a timely manner. If you want to contribute feel free to create a merge request and open an issue discussing a potential bug or feature. You are free to use this software in any personal or commercial project.

Quick-Start

To install the package-obfuscator run the following command:

pip install package-obfuscator

To use the package-obfuscator either use the cli...

package-obfuscate my_secret_package

or use the package-obfuscator in a script:

import os
import package_obfuscator

current_folder = os.path.dirname(os.path.realpath(__file__))
package_folder = os.path.join(current_folder, 'my_secret_package')

package_obfuscator.obfuscate(package_folder)

CLI

The CLI provides the following options

Argument Description Default
package_location (positional) An absolute or relative path to the package that should be obfuscated required
--output / -o An absolute or relative path to a folder in which to place the obfuscated package content. If this argument is not provided the obfuscation will take place in the originally provided package_location. package_location
--force-overwrite / -f If the output folder is existent the obfuscator will exit. You can disable this behaviour and achieve a hard overwrite if you add this option
--short-filenames / -s By adding this option, shorter filenames will be generated for the obfuscated files by avoiding the default random uuid in filenames.
--py-cache-folder-name / -p Provide a custom filename for the pycache generated folder.

Python API

package_obfuscator

package_obfuscator.obfuscate(package_dir, [output=..., [force_output_overwrite=False]])

Argument Description Required / Optional
package_dir The absolute or relative path to the package directory. Required
output The absolute or relative path to the directory in which to place the obfuscated files. If not provided the obfuscation will take place within the package_dir. Optional
force_output_overwrite If the output folder exists when running the code the obfuscator will exit with an exception. If you want to force an overwrite you should provide this argument with True. Optional
short_filenames By adding this option, shorter filenames will be generated for the obfuscated files by avoiding the default random uuid in filenames. Optional
py_cache_folder_name Provide a custom filename for the pycache generated folder. Optional

When to use the package-obfuscator

The package-obfuscator should be used prior to releasing your python package in any way. The easiest way is to use the following code structure. Let's assume you are developing a module called my_module. Your directory structure will look something like this:

my-module-repository
  > my_module_source
      > sub_module
          script2.py
      __init__.py
      script1.py
  setup.py

Then it is suggested to use the package-obfuscator as a package in the setup.py.

import package_obfuscator
package_obfuscator.obfuscate('my_module_source', output='my_module')

setup(
    name='my_module',
    version='0.0.1',
    packages=find_packages(include=['my_module', 'my_module.*'])
)

Your wheel will then only include obfuscated code.

How does the obfuscation work?

The obfuscation works by compiling the code within each package-related python file into binary code. It will find all python files (*.py) recursively and ignore all other files. The binary code is then saved into separate files. The original file will execute the binary file using the exec command and the marshal library.

How safe is the obfuscation method?

It is important to note that the obfuscation is not completely secure. It is possible to reverse-engineer your code using the binary files. But even when converting the code back only excerpts of the code will be humanly readable straight away. This method of obfuscation is recommended for code that is not mission-critical but should nevertheless not be deployed as human-readable code.

Test

docker build --rm -t test .
docker run --rm -t -v $(pwd):/root/${PWD##*/} test bash test.sh

Metadata

Release files for package-obfuscator 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for package-obfuscator 1.0.2
File Size Uploaded Provenance
package_obfuscator-1.0.2.tar.gz 7.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for package-obfuscator 1.0.2
File Interpreter ABI Platform
package_obfuscator-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.6 kB

Release files / package_obfuscator-1.0.2.tar.gz

Download URL package_obfuscator-1.0.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ed207a6894821c967e297e0c308cad8d16f6a7f94c8820c1e4bfb899d618aa2f
BLAKE2b-256 checksum
How to use checksums
b1f2ff2e7b234b9866e1f98fdeb04373fae2d04f09d99c6187ca5c0a78633573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / package_obfuscator-1.0.2-py3-none-any.whl

Download URL package_obfuscator-1.0.2-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b416c75c768153f5de99e860d12bf428e823d520773ac40e2bb13d72c8b75feb
BLAKE2b-256 checksum
How to use checksums
68002236e09eab22a11dea00987e47231d1ba0d9189b60cd0f6a131165fd3882
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Security for package-obfuscator 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page