Skip to main content

Python library for Apple's PKL.

Project description

[!CAUTION]

THIS LIBRARY IS CURRENTLY PRE-RELEASE

pkl-python is currently major version v0, and breaking changes will happen between versions.

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.

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

pkl_python-0.1.19.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

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

pkl_python-0.1.19-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file pkl_python-0.1.19.tar.gz.

File metadata

  • Download URL: pkl_python-0.1.19.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pkl_python-0.1.19.tar.gz
Algorithm Hash digest
SHA256 0d0eccbbe52c8e2b5e486dd49a73676a6ba82803fbc341b81a520e986d772eef
MD5 1f4e9c695730803f0d58b6893ef873e6
BLAKE2b-256 1e37a7485f182467e09d8fc45b0dd9d31e58f0fe694e22b6f59547445be20168

See more details on using hashes here.

File details

Details for the file pkl_python-0.1.19-py3-none-any.whl.

File metadata

  • Download URL: pkl_python-0.1.19-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pkl_python-0.1.19-py3-none-any.whl
Algorithm Hash digest
SHA256 526bd1e3a4ec09d8786ed417c879b8f30437a40559ec01496c720346ef5ccdd3
MD5 04ab4e9d7dca3c8f48a53f547469135b
BLAKE2b-256 ecbc68c562b79c6ead2668ffe48fef810ae6208fb9c31dce72045d8021e63be6

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