Skip to main content

Python package baking utility

Project description

# PyBaked

What is it?

This library allows you to "bake" your(or not) packages into a single file that can be imported as a normal package

But IDEs will not support this, only, if someone create an extension

Usage

There are two command-line tools: baked-make and baked-read

baked-read

Created for reading "baked" python packages. Reads metadata, creation date, packages and modules in it.

Usage:

baked-read backed_package_name

backed_package_name it is a file with extension .py.baked

Note: you can pass name without extension(tool will add it)

Or, to read module source from it:

baked-read backed_package_name -m module_name

module_name can be get from parentheses from first example run


baked-make

Created for "baking" packages into a single file.

Usage:

baked-make package_name -o baked_package_name

package_name is the name of the source package

baked_package_name is the name of the output "baked" package (this is optional argument)

All optional parameters and description:
-H / --hash - Hash modules in the package (if the hash not match in the package - loader will not load this package)
-m / --metadata - JSON formated metadata that will be serialized and baked into a file
-M / --metadata-file - path to a metadata JSON formatted file
-o / --output - "baked" package name


Importing

To import "baked" package you need to init loader first:

import pybaked


pybaked.loader.init()

And then, you can import "baked" packages as normal python packages:

import baked_package_name

BakedMaker

Class created for creating baked packages (used by baked-make tool)

Usage:

import pybaked

# Make baked package from real existent package
pybaked.BakedMaker.from_package(
    "pybaked",
    hash_content=True,
    metadata={"a": "b"}
).file("baked_package_name.py.baked")

This code will "bake" package pybaked into a single file named "baked_package_name.py.baked"

Example, without real existent package:

import pybaked

pybaked.BakedMaker(
    hash_content=True,
    metadata={"a": "b"}
).include_module(b"module_name", b"print(\"Source code\")").file(
    "baked_package_name"
)

Note: BakedMaker.include_module first parameter is a module name in an import format (example: subpackage.module_name)

For example, if you pass some.py into BakedMaker.include_module it will be added as py module in the some subpackage of the "baked" package


BakedReader

Class created for reading "baked" packages (used by baked-read tool)

Usage:

import pybaked

reader = pybaked.BakedReader("baked_package_name.py.baked")

# Package creation date
print("Package created at:", reader.created)

# Package metadata
print("Package metadata:", reader.metadata)

# Package modules (module_name, source_offset)
print("Package modules:", reader.modules)

# Package modules as dict {module_name: source_offset}
print("Package modules as dict:", reader.modules_dict)

# Package subpackages
print("Package subpackages:", reader.packages)

Note: reader combines package_name and module_name separating by dot

For example, when module_name is a "__init__" and package_name is a "baked_package". Then reader will return it as baked_package.__init__.

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

pybaked-0.0.16.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

pybaked-0.0.16-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file pybaked-0.0.16.tar.gz.

File metadata

  • Download URL: pybaked-0.0.16.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.2 Linux/6.1.0-22-amd64

File hashes

Hashes for pybaked-0.0.16.tar.gz
Algorithm Hash digest
SHA256 b8c770ec17c61c3f5ea14e5f77adadc058d98f171ccafe5060d863d032ce9cc9
MD5 6d0c6a4ad452d87506564e8c9498fc20
BLAKE2b-256 5a484f82ced644a77b49bd49e40364546ba625a60f987b781cacda3a69c1a6d1

See more details on using hashes here.

File details

Details for the file pybaked-0.0.16-py3-none-any.whl.

File metadata

  • Download URL: pybaked-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.2 Linux/6.1.0-22-amd64

File hashes

Hashes for pybaked-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 1377cf0743b22194474410002039878d91e4788f4b50cd34cd46bc1596375e2f
MD5 61eb3d3e360855143b72211059926f9f
BLAKE2b-256 0ffeeab65d17e140e6733e809f079fd0f1b401f323ec1cbd569f7395b3211c97

See more details on using hashes here.

Supported by

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