arcp (Archive and Package) URI parser and generator
arcp is a Python library (current version 0.2.1) designed for creating and parsing arcp (Archive and Package) URIs. These URIs are used to identify or refer to hypermedia files bundled within an archive or application package, such as a ZIP file. The library focuses solely on URI generation and parsing and does not provide functionality for interacting with archive files (like `zipfile`) or making network requests (`urllib.request`). Its release cadence appears slow, with the last update to PyPI in February 2020.
Common errors
-
AttributeError: module 'arcp' has no attribute 'read_archive'
cause Attempting to use `arcp` to read the contents of an archive file directly.fixThe `arcp` library is for URI parsing and generation only. To read an archive, use appropriate Python modules like `zipfile` or `tarfile`. For example: `import zipfile; with zipfile.ZipFile('my_archive.zip', 'r') as zf: ...` -
arcp.InvalidURI: Invalid URI authority 'http'
cause Trying to parse a non-arcp URI (e.g., an HTTP URL) with `arcp.parse()`.fix`arcp.parse()` is specifically designed for 'arcp' scheme URIs. Ensure the input string starts with 'arcp://' before parsing. For other URI schemes, use `urllib.parse`.
Warnings
- gotcha The `arcp` library strictly handles URI parsing and generation. It does NOT provide functionality for accessing, reading, or writing content within actual archive files (e.g., ZIP, JAR) or fetching them via network protocols.
- deprecated The `arcp` library has seen no significant updates or releases since February 2020. While functional for its stated purpose, it may not be actively maintained.
Install
-
pip install arcp
Imports
- arcp
from arcp import parse, serialize
import arcp
Quickstart
import arcp
# Example 1: Creating an arcp URI
uri_str = arcp.serialize(authority='uuid', name='32a423d6-52ab-47e3-a9cd-54f418a48571', path='/doc.html')
print(f"Generated URI: {uri_str}")
# Expected: arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html
# Example 2: Parsing an arcp URI
parsed_uri = arcp.parse("arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/metadata.json")
print(f"Parsed URI scheme: {parsed_uri.scheme}")
print(f"Parsed URI authority: {parsed_uri.authority}")
print(f"Parsed URI path: {parsed_uri.path}")
print(f"Parsed URI name: {parsed_uri.name}")
print(f"Parsed URI identifier: {parsed_uri.identifier}")