Python library to read and write Silkroad Online PK2 files
Project description
PK2API
Based on: https://github.com/JellyBitz/JMX-File-Editor
Python library to read and write data into the PK2 file format from Silkroad Online.
Features
- Fast search O(1)
- Create new PK2 files
- Create new paths recursively if does not exist
- Full read/write support
Installation
pip install pk2api
Or install from source:
pip install -e .
Usage
from pk2api import Pk2Stream
key = "169841" # Default SRO key
# Read-only mode
with Pk2Stream("/path/to/Media.pk2", key, read_only=True) as pk2:
# Get file content
file = pk2.get_file("Type.txt")
if file:
content = file.get_content()
print(content.decode("utf-8"))
# List files from root folder
root = pk2.get_folder("")
print("Files:")
for path in root.files.keys():
print(f" - {path}")
# List folders from root folder
print("Folders:")
for path in root.folders.keys():
print(f" - {path}")
# Read-write mode
with Pk2Stream("/path/to/Media.pk2", key) as pk2:
# Add & remove folder
pk2.add_folder("test/new_folder")
pk2.remove_folder("test/new_folder")
# Add & remove file
pk2.add_file("test/new_file.txt", b"Hello World")
pk2.remove_file("test/new_file.txt")
API Reference
Pk2Stream
Main class for reading and writing PK2 archives.
Pk2Stream(path: str, key: str, read_only: bool = False)
Methods:
get_folder(path: str) -> Pk2Folder | None- Get folder by pathget_file(path: str) -> Pk2File | None- Get file by pathadd_folder(path: str) -> bool- Create folder (recursive)add_file(path: str, data: bytes) -> bool- Add or update fileremove_folder(path: str) -> bool- Remove folder and contentsremove_file(path: str) -> bool- Remove fileclose()- Close the stream
Pk2Folder
Represents a folder within a PK2 archive.
Properties:
name: str- Folder nameparent: Pk2Folder | None- Parent folderoffset: int- Byte offset in streamfiles: dict[str, Pk2File]- Files in this folderfolders: dict[str, Pk2Folder]- Subfolders
Methods:
get_full_path() -> str- Get full path from root
Pk2File
Represents a file within a PK2 archive.
Properties:
name: str- File nameparent: Pk2Folder- Parent folderoffset: int- Byte offset in streamsize: int- File size in bytes
Methods:
get_full_path() -> str- Get full path from rootget_content() -> bytes- Read file content
Known Issues
- New folder/file names are saved in lowercase
Requirements
- Python 3.10+
Special Thanks!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pk2api-1.2.0.tar.gz.
File metadata
- Download URL: pk2api-1.2.0.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4529f049440ce41cea69eaad4f557c489df7eae15b7fac2733d0b22ed93395c3
|
|
| MD5 |
c0d85498463b711c56ea6d41da178795
|
|
| BLAKE2b-256 |
81d378dae756f2fe072acda05f0ccb5012b1c2f6e2302876ffdfe20c210858c5
|
Provenance
The following attestation bundles were made for pk2api-1.2.0.tar.gz:
Publisher:
publish.yml on dadav/pk2api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pk2api-1.2.0.tar.gz -
Subject digest:
4529f049440ce41cea69eaad4f557c489df7eae15b7fac2733d0b22ed93395c3 - Sigstore transparency entry: 821482893
- Sigstore integration time:
-
Permalink:
dadav/pk2api@41e91dee2056bb13c20dd5652ad3322993a79ad2 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/dadav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@41e91dee2056bb13c20dd5652ad3322993a79ad2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pk2api-1.2.0-py3-none-any.whl.
File metadata
- Download URL: pk2api-1.2.0-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52a02c4b4a4e4b455f15b271eb08076ef4f82744e090972a0d79fd5583aa0222
|
|
| MD5 |
0ead5f0ee111a20094d7087aeb34b5d4
|
|
| BLAKE2b-256 |
59cacbaa3a8fe666cc2f7719cdb6166216792985784d73c82bb6f8b3857bb78a
|
Provenance
The following attestation bundles were made for pk2api-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on dadav/pk2api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pk2api-1.2.0-py3-none-any.whl -
Subject digest:
52a02c4b4a4e4b455f15b271eb08076ef4f82744e090972a0d79fd5583aa0222 - Sigstore transparency entry: 821482900
- Sigstore integration time:
-
Permalink:
dadav/pk2api@41e91dee2056bb13c20dd5652ad3322993a79ad2 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/dadav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@41e91dee2056bb13c20dd5652ad3322993a79ad2 -
Trigger Event:
push
-
Statement type: