[HN Gopher] Show HN: Pip Imports in Deno
___________________________________________________________________
Show HN: Pip Imports in Deno
deno_python 0.3.1 adds support for importing python pip packages
directly in JavaScript! Fun and useful, slightly cursed.
Author : eliassjogreen
Score : 175 points
Date : 2023-08-11 09:30 UTC (1 days ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| qazxcvbnm wrote:
| Is there an equivalent for Node? I'm glad I haven't needed it
| since, but I couldn't find anything nearly so seamless when I
| last looked.
| swyx wrote:
| why can't you just exec a python shell command to do the same
| thing? i'm actually slightly puzzled that "FFI" is its own
| thing when every language has a way to exec shell commands
| nathan_phoenix wrote:
| You can if you are just executing a static python script
| never changes.
|
| But if you want to call some python functions with your TS
| input then you would need to serialize the TS input, pass it
| as an arg to the script, there deserialize it and then call
| the python function with the input. And if you wanted to call
| multiple python functions then your first arg to the python
| script would need to be the name of the function, only then
| the serialized data. Plus you would need to implement a
| switch case on the python side to execute the right function.
| swyx wrote:
| right. ok. thats not hard^? like at all? and in fact ive
| had multiple bugs that ultimately had to do with
| serialization being quietly abstracted over for me that if
| i had just handrolled it myself i probably wouldve been
| consciously aware of my bad choices.
|
| ^i know this is probably arrogance out of naivete, just
| teasing out what exactly i dont know that i dont know about
| what FFI does.
| viraptor wrote:
| There are limits to what the commandline arguments can
| take. And even if you fallback to files instead, you
| still need to serialise a potentially huge amount of
| data. (Wanna serialise a 1GB tree that is going to get
| only one lookup in each call to the script?) On top of
| that, you're missing any chance of in-memory caching,
| because the script call can't preserve that, while FFI
| could. Then there are things that are just not possible
| to serialise like pointers to mapped memory, file
| descriptors (outside of unix sockets), etc.
|
| Finally even if everything works, a command execution and
| parsing results is massively slower than a function call.
| So yeah, there's lots of restrictions on what you can
| practically do that way.
| djdev wrote:
| [dead]
| rolisz wrote:
| So you can now shoot yourself in the foot with both Python and
| JavaScript package management?
| Tajnymag wrote:
| The package targets deno. It can be imported directly without
| using any package manager.
| bandergirl wrote:
| [dead]
| agumonkey wrote:
| maybe they will cancel each other ?
| rolisz wrote:
| Hah, we wish. In practice what will happen is we'll get the
| black hole spacetime disruption due to NPM package weight
| combined with dependency hell from pip
| IshKebab wrote:
| Deno fixed the mess of JavaScript package management... But
| even NPM is light years ahead of Python. I have no idea why
| you'd want to inflict that on yourself once you've escaped it.
| I guess the only reason is there's some Python package that you
| have no option but to use.
| saiojd wrote:
| Javascript's package management is so much better than Python's
| IMO...
| ShamelessC wrote:
| Package management, sure. The packages themselves leave a lot
| to be desired in JS.
| throwawaymaths wrote:
| I believe that's the joke, the two package systems have
| orthogonal nightmares
| yohskar wrote:
| Nice !
| amelius wrote:
| Does this work for packages like PyTorch too, in GPU mode?
| eliassjogreen wrote:
| Yes, it uses your native python installation so everything that
| works with python should work with this.
|
| I have had success running sbert, faster-whisper and various
| other GPU accelerated packages.
| jadbox wrote:
| It would be magical if we also got typescript type hints too.
| Tajnymag wrote:
| That sounds like a completely different beast of a tool
| vorticalbox wrote:
| Not so much you can use inspect [0] to see a whole lot of
| information. I used this at work to auto generate json scheme
| of passed functions for openAI function feature [1]
|
| [0] https://docs.python.org/3/library/inspect.html
|
| [1] https://platform.openai.com/docs/guides/gpt/function-
| calling
| willquack wrote:
| This is awesome and the right level of cursed!
|
| Reminds me of PythonMonkey, which provides really high level
| bindings to SpiderMonkey in Python. It ships as both a pip
| package and a standalone js runtime, the latter of which is very
| similar to this project!
|
| https://github.com/Distributive-Network/PythonMonkey#pythonm...
| arjvik wrote:
| Connecting these two would be _even more cursed_
| punnerud wrote:
| Let Python from Deno write to SQLite, Deno serve a webpage that
| use JS to accessing <<static>> SQLite using HTTP range requests,
| and we have come full circle
|
| (Joke, but would be a cool prototype)
| arthur2e5 wrote:
| The organization name "denosaurs" very roughly works for a
| combination of deno and python too: snakes fall into the clade of
| Lepidosaurs. Dinos are Archosaurs.
|
| I wonder if there's another programming language featuring a
| reptile. What's this "Lizard" language Duckduckgo's telling me
| about?
| pjot wrote:
| I always get a kick out of well named projects - good eye!
| mbStavola wrote:
| Maybe not to the same degree, but Zig!
|
| Its users are even called Ziguanas.
| mellosouls wrote:
| Cobra
|
| https://en.m.wikipedia.org/wiki/Cobra_(programming_language)
|
| And pushing it a bit as "a language":
|
| Anaconda
| motform wrote:
| A truly incredible feat of FFI!
| throwaway888abc wrote:
| I'm using this package so far.
|
| https://github.com/hmenyus/node-calls-python
|
| Excited to compare to Deno. Thanks guys!
| skybrian wrote:
| Next step would be getting ObservableJS running and using it to
| write notebooks. (There is a vscode plugin for this that might be
| adapted.)
| parabyl wrote:
| Super cool! Fun, useful and slightly cursed indeed
| kwhinnery wrote:
| ngl this is a little cursed, but awesome
| baq wrote:
| Can't decide if I'm more amazed or terrified at the prospect of
| fighting both JS and Python package managers in the same process.
| tomcam wrote:
| Deno package management is saner but more limited
| re-thc wrote:
| Is Deno really performing so badly that it has to get PIP'ed? I
| thought NodeJs would be first...
| vorticalbox wrote:
| Not at all but if you have an api in js and you want to do any
| sort of machine learning, ai, forecasting well all the best
| tools are in python.
|
| The you have two choices you rewrite your api into python or
| you call python from your js.
| FireInsight wrote:
| You can also do this in Nim, which basically means you can write
| any program you could in Python with libraries in Nim.
| https://github.com/yglukhov/nimpy
| abusaidm wrote:
| This is really fun indeed, well done, I like it. It's funny how
| you decided to demo it with a library that does lots of c++
| bindings it's self. Now someone can put a wrapper around this to
| hide the python imports, so we can claim JS is the only language
| we need.
| rowanG077 wrote:
| Everyday we stray further from gods light.
___________________________________________________________________
(page generated 2023-08-12 23:01 UTC)