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.17.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

pybaked-0.0.17-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pybaked-0.0.17.tar.gz
Algorithm Hash digest
SHA256 fa34b8a5edda4d5c8c85b3b887bb2adf0c0a26b1a84572a6680372211c142a17
MD5 403ac26a88c3872945e0806035c3873b
BLAKE2b-256 5c4c5093d5c7ce4580f820a2da811bd61dc4a27a0066e39ba371576b0fb1c46a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pybaked-0.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 65198b39448a1373a8ddac3a949b5bb181cf0b4eee9f54911f153fb3e77623ab
MD5 29097e7a5f4aa3fe61ec6f4f75c1b245
BLAKE2b-256 e421b90e19b62827655d8bb0c1029df21d3ca0517cc57cc893bbe5c76d3edeb0

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