Python library for Apple's PKL.
Project description
[!CAUTION]
THIS LIBRARY IS CURRENTLY PRE-RELEASE
pkl-python
is currently major versionv0
, 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pkl_python-0.1.16.tar.gz
.
File metadata
- Download URL: pkl_python-0.1.16.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae2d61cfd44df5dae08a70361c725d7b2e5b0eef74ca210a3ccd609e05ecc672 |
|
MD5 | 812f5ed8a50f8a60cf8e6700e7e9f897 |
|
BLAKE2b-256 | eb9593d0db49ab6eb69df693f4a25ba6dc13f968e2120355d082764a84f8934d |
File details
Details for the file pkl_python-0.1.16-py3-none-any.whl
.
File metadata
- Download URL: pkl_python-0.1.16-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e98c7ebf82da1e656821bd3cc31b31bf5bd35028797245c8dbff65393d0cb453 |
|
MD5 | 65ed21814883d34204c696a2768edafc |
|
BLAKE2b-256 | 08e7fd2da605ca2e9be6bbbc554b24a46086bc9ad8594212cfec6ca83642e203 |