KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Is there a way to load a q-script from the internet without saving it at disk?

  • Is there a way to load a q-script from the internet without saving it at disk?

    Posted by vivo on July 30, 2022 at 12:00 am

    Currently if I want to import a q-script, e.g. sp.q, from the internet, I need to save it to disk and then load it.

    system "wget https://raw.githubusercontent.com/KxSystems/kdb/master/sp.q";

    \l sp.q

     

    But if I want to do the l to the url directly without saving sp.q to disk, it doesn’t work:

    \l https://raw.githubusercontent.com/KxSystems/kdb/master/sp.q

     

    If I want to import the q-script without saving it, the only way I can do is to parse sp.q paragraph by paragraph manually:

    myText:system "curl https://raw.githubusercontent.com/KxSystems/kdb/master/sp.q";

    value “” sv myText[til 5]; // import the 1st paragraph
    value “” sv myText[5 _ til 10]; // import the 2nd paragraph

     

    Is there a better way to do this?

    vivo replied 9 months, 1 week ago 2 Members · 1 Reply
  • 1 Reply
  • davidcrossey

    Member
    July 31, 2022 at 12:00 am

    Hi vivo,

    To load a q script it needs to be loaded from the local disk.

    You could also use .Q.hg to download the file directly into your process with either of the following as examples:

    q)"rn" vs .Q.hg `:https://raw.githubusercontent.com/KxSystems/kdb/master/sp.q 
    /or 
    q)ssr[;"rn";""] .Q.hg `:https://raw.githubusercontent.com/KxSystems/kdb/master/sp.q

    However with this approach you’d need a lot of customization per code block to execute it locally.

    If you are downloading the script to the local q process, why would you not store it on disk anyway? For example, re-loading later instead of multiple downloads.

    Kind regards,

    David

Log in to reply.