Skip to content

command-line tool #151

Closed
Closed

Description

@pchampin

It would be great to have a command-line tool based on PyLD, for doing basing JSON-LD transformations.
So I hacked one for my own purposes. It is here:
https://gist.github.com/pchampin/9416e423efe9925adaee536a3abdaf4c

Feel free to include it if you think it is a good idea.

Activity

  1. added this to the v3.0.0 (JSON-LD 1.1) milestone on Feb 3, 2026
  2. modified the milestones: v4.0.0 (migration to rdflib), on May 19, 2026
  3. modified the milestones: , v4.0.0 (migration to rdflib) on Jun 5, 2026
  4. anatoly-scherbakov commented on Jul 25, 2026

    @anatoly-scherbakov
    Collaborator

    Thanks for the suggestion and for the gist — useful prior art.

    A CLI cannot land until local files and remote contexts can both be loaded in one operation. Status:

    1. FileDocumentLoader — in progress on branch file-document-loader. Serves file: URLs (and scheme-less absolute paths) only, with optional root confinement.
    2. Scheme dispatch — tracked in Add ChoiceBySchemeDocumentLoader for scheme-based document loading #300 as ChoiceBySchemeDocumentLoader, so a local document with a remote @context can be processed.
    3. CLI — after (1) and (2), build a Typer-based pyld tool.

    Proposed CLI shape

    • One Typer command per jsonld API function: expand, compact, flatten, frame, to-rdf, from-rdf, normalize.
    • Options for each command derived from the matching *Options TypedDict in lib/pyld/options.py.
    • Input from an optional positional path-or-URL argument, falling back to stdin; JSON or N-Quads on stdout.

    Packaging: PyLD[cli] extra

    Gate the CLI behind an optional extra so a bare pip install PyLD stays lean:

    pip install "PyLD[cli]"

    That extra would install typer and register the pyld console script. lib/pyld/cli.py should raise a clear ImportError naming the extra when typer is missing, so a half-installed environment never yields an obscure failure.

    Two packaging notes:

    • setup.py currently imports distutils.core.setup, which silently ignores entry_points. Registering any console script requires switching to setuptools.setup first.
    • The yaml-ld package on PyPI already installs a pyld console script, so installing both packages in one environment would clash over the executable name.

    Loader wiring

    The CLI should pass a scheme-dispatching loader (issue #300) as documentLoader per operation, and leave _default_document_loader in lib/pyld/jsonld.py alone. Serving file: by default would let any document with "@context": "file:///etc/passwd" read local files.

  5. linked a pull request that will close this issueAdd pyld command-line interface #305on Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions