Skip to main content

pkl-python - Pkl Bindings for Python

Python binding for Apple's Pkl language.

Getting Started

Installation

pip install pkl-python

Basic Usage

Here's how you can start using pkl-python to load a PKL module:

import pkl

config = pkl.load("path/to/pkl/example_module.pkl")
config = pkl.loads("a: Int = 1 + 1")

Code Generation

As Python is a dynamic language, codegen is not strictly necessary. However, codegen lets you expect contents of pkl files within Python modules.

pkl-gen-python path/to/pkl/example_module.pkl

TODO

  • (codgen) pip binary installation
  • (codgen) gatherer depth-first ordering
  • (codgen) clean up code

Advanced Features

import pkl

config = pkl.load("./tests/types.pkl")
config = pkl.load("./tests/types.pkl", expr="datasize")
config = pkl.load(None, module_text="a: Int = 1 + 1")
config = pkl.load("./tests/types.pkl", debug=True)

pkl.load Parameters Detail

For details on the parameters, refer

Custom Readers

It is possible to add module or resource or module readers:

from typing import List
from dataclasses import dataclass

import pkl
from pkl import (
    ModuleReader, ResourceReader, PathElement,
    ModuleSource, PreconfiguredOptions, PklError,
)

class TestModuleReader(ModuleReader):
    def read(self, url) -> str:
        return "foo = 1"

    def list_elements(self, url: str) -> List[PathElement]:
        return [PathElement("foo.pkl", False)]

opts = PreconfiguredOptions(
    moduleReaders=[TestModuleReader("customfs", True, True, True)]
)
opts.allowedModules.append("customfs:")
config = pkl.load("./tests/pkls/myModule.pkl", evaluator_options=opts)

Appendix

Type Mappings

While in pre-release they are subject to change.

Pkl type TypeScript type
Null None
Boolean bool
String str
Int int
Int8 int
Int16 int
Int32 int
UInt int
UInt8 int
UInt16 int
UInt32 int
Float float
Number float
List list
Listing list
Map dict
Mapping dict
Set set
Pair pkl.Pair
Dynamic dataclasses.dataclass
DataSize pkl.DataSize
Duration pkl.Duration
IntSeq pkl.IntSeq
Class dataclasses.dataclass
TypeAlias typing
Any typing.Any
Unions (A|B|C) typing.Union[A|B|C]
Regex pkl.Regex

Contributing

Contributions are welcome! If you'd like to contribute, please fork the repository and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

License

PKL is released under the MIT License. See the LICENSE file for more details.

Contact

For support or to contribute, please contact jwyang0213@gmail.com or visit our GitHub repository to report issues or submit pull requests.

Metadata

Release files for pkl-python 0.1.19

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

Source distribution (sdist)

Source distribution for pkl-python 0.1.19
File Size Uploaded Provenance Actions
pkl_python-0.1.19.tar.gz 24.1 kB Without provenance Details for pkl_python-0.1.19.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pkl-python 0.1.19
File Interpreter ABI Platform Actions
pkl_python-0.1.19-py3-none-any.whl Python 3 none any Details for pkl_python-0.1.19-py3-none-any.whl

Total release size: 45.4 kB

Release files / pkl_python-0.1.19.tar.gz

Download URL pkl_python-0.1.19.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0d0eccbbe52c8e2b5e486dd49a73676a6ba82803fbc341b81a520e986d772eef
BLAKE2b-256 checksum
How to use checksums
1e37a7485f182467e09d8fc45b0dd9d31e58f0fe694e22b6f59547445be20168
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / pkl_python-0.1.19-py3-none-any.whl

Download URL pkl_python-0.1.19-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
526bd1e3a4ec09d8786ed417c879b8f30437a40559ec01496c720346ef5ccdd3
BLAKE2b-256 checksum
How to use checksums
ecbc68c562b79c6ead2668ffe48fef810ae6208fb9c31dce72045d8021e63be6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for pkl-python 0.1.19

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