251 points · by ducaale · 5y ago · 96 comments
These days I try to avoid interpreted CLI tools, you never know when they’re going to stop working.
Rust/Go CLI tools basically work on Linux, Max, Windows without too much fuss.
Wish someone would rewrite Homebrew in Rust!
Things like httpie, jupyter, etc should be provided as pyz and binaries as well, not just pip installable, but python devs don't do that really often.
It's a shame, because cli tools should be black boxes, people should not have to think about the implementation. I regularly see cli python tools that output stack traces on errors, and it should not happen.
Anyway, if you want those tools to be always around, I really encourage you to grap a usb stick, and put them on there as pyz and binaries. It's always nice to have them at hand.
Here is an example procedure for both (run them in a venv).
For pyz files:
python -m pip install shiv --user # (Yes, I realize how ironic this is).
Then: python -m shiv httpie -o http.pyz -c http
(download httpie, and creates a http.pyz file that will contains httpie and all it's dependancies, plus code to trigger the http command when called)This will let you do "python http.pyz" anywhere you have a modern python and enjoy httpie without the need to pip install it.
For an exe (this is an example on linux, the commands are a bit different for windows and mac):
python -m pip install nuitka httpie --user
You need to have a C compiler and python headers around as well (gcc on linux will do, E.G: sudo apt install build-essential python3-dev on ubuntu).Then:
python -m nuitka $(which http) --onefile --linux-onefile-icon /usr/share/pixmaps/python3.xpm --follow-imports --assume-yes-for-downloads
Wait quite a bit.Now you have a nice stand alone AppImage you can call with ./http.bin to be used on any linux system, and not care if Python is installed to play with httpie.
Here are the resulting files (available for 5 days) so you can see what it looks like:
https://drop.chapril.org/download/a335a8e92f98ee02/#fHC1SvOw...
Nuitka produces a standalone exe so no need to install python.
Basically Rust ignores SIGPIPE, so if you don't use write!() or handle SIGPIPE yourself, large amounts of data going through a shell pipe can result in a panic.
I wonder how many Rust CLI tools have the issue.
(EDIT: talking about Python packages specifically, not so sure about other things)
As you say, if something doesn't work due to conflicting dependencies, usually creating a virtualenv solves it. I don't bother these days, as just installing everything with --user tends to always work.
Since you are sort of making the connection for Homebrew to work without fuss on Linux and Windows as well, if implemented in Rust, I am asking myself what it would offer that a user of Linux and Windows is missing?
Ordinary Linux distributions already have a package management and there is scoop and chocolaty for Windows.
I mainly want it to be rewritten in a compiled language for performance reasons, it's a sluggish beast. I haven't tried to use it on Linux (where it has some support), and definitely not on Windows (winget/chocolatey would be my port of call there).
Examples of tools I use across operating systems that were written in Rust/Go, that pretty much are drop an executable somewhere and run:
ripgrep, starship, tailscale, terraform, vault, etc.
Whereas when something is written in Python, Ruby or similar, I'm rolling the dice, and I'm only an apt-get or dnf away from it breaking when I really need it.
Personally, being a user of Homebrew on macOS I’ve been thinking about wanting brew to be rewritten in Rust too. My own reason being that I think it would be faster when run, compared to the version they have of it currently which can be quite slow sometimes. And because I like Rust as a language and for its memory safety features. So I’d rather see brew implemented in Rust than in say C or C++, if a compiled language was to be used.
The binaries of Rust/Go replicas should also be updated but to my experience few package managers provide packages for apps written in those languages.
I think that's exactly the kind of complexity arusahni was referring to. Being able to deploy a single binary with `go get` or `cargo build` without worrying about anything else is really convenient.
I guess it depends on the use case though, I use Python extensively at work and have little complaints.
Who wants to deal with pyenv or whatever when you can just get a static binary?
For users of Arch Linux, I submitted an AUR package: https://aur.archlinux.org/packages/ht-bin/.
*Mumbles ubuntu-based user"
So all you need to install this now is:
pacman -Syu xhAdding HEAD as one of the methods would be welcome so we could get headers without pulling the whole page. Also, I did find the arguments for the -p switch in the source, but that should probably go in the README too.
Thank you so, so much.
Unfortunately the name clashes with a binary that's part of TeXlive:
$ pacman -Qo /usr/bin/ht /usr/bin/ht is owned by texlive-core 2020.57066-1
But I guess then the packagers will need to rename the "ht" binary to "http" (and add a conflict with httpie) when packaging.
Use --offline to see the request but not perform it:
http --offline get google.com
GET / HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 5
Content-Type: application/json
Host: google.com
User-Agent: HTTPie/2.4.0
Pipe stuff to httpie to put it in the payload: echo "Hello HN" | http --offline get google.com
GET / HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 13
Content-Type: application/json
Host: google.com
User-Agent: HTTPie/2.4.0
Hello HN
And use http-prompt, because it's awesome: https://github.com/httpie/http-promptHTTPie requires Python so Ht could have another advantage being easier to install.
We are also developing an HTTP client in Rust using curl (it’s an overwhelmed place!), it’s still very young but I link here anyway https://hurl.dev
[edited] there is already a Windows version, so really good job!
> The release page contains prebuilt binaries for Linux, macOS and Windows.
Which could possibly use Hyper under the hood :-P
Also, please post another Show HN when the backlog is almost done.
>I see that you have a “HTTPie feature parity checklist” (issue #4) on the issues list. Is that the sole indicator (aside from bugs) of what a version 1.0 would be like?
Yes, that pretty much sums it. Also The list might expand if I notice other HTTPie features I forgot about.
% hyperfine 'http get EXAMPLE.COM' 'ht get EXAMPLE.COM' -w 10 -r 100
Benchmark #1: http get EXAMPLE.COM
Time (mean ± σ): 200.8 ms ± 7.4 ms [User: 178.9 ms, System: 21.1 ms]
Range (min … max): 166.5 ms … 221.0 ms 100 runs
Benchmark #2: ht get EXAMPLE.COM
Time (mean ± σ): 22.7 ms ± 3.2 ms [User: 8.7 ms, System: 5.6 ms]
Range (min … max): 15.6 ms … 31.3 ms 100 runs
Summary
'ht get EXAMPLE.COM' ran 8.84 ± 1.27 times faster than 'http get EXAMPLE.COM'So, kudos!
It's basically curl (fast) plus simpler and easier interface and pretty printers. For performance in shell scripts you can use curl, and for troubleshooting the IO time dominates anyway.
There's definitely a noticeable delay on my machine with starting up the python interpreter. Enough that it dominates most actual request times to fast servers. (`http get www.google.com` is ~460ms while `ht get www.google.com` is ~130ms)
For a tool I'm constantly using to check APIs I'm developing, I really appreciate snappy commands that give me results that feel instantaneous.
With about 0.5s startup time, it means every 120 requests add a full minute to the final time. And I had to scrape ~125K URLs back then.
For a daily casual flow 0.5s startup time might not be much (although people like myself get irritated by that as well but I do recognize it's a minor inconvenience). But when doing mass-scripting such delays can very easily compound to non-trivial time inefficiencies.
I would like to understand from where a question like this comes, I understand different people have different experiences and backgrounds, but being on this site I would assume this would be kinda obvious.
Can you share anything about your experience that can help me understand it?
As another commenter mentioned I suspect what's being measured here is the Python startup time rather than performance once things are running.
My guess would be a faster to start interpreter (like lua or v8) would rival ht performance, while a slower to start compiled language like the JVM would be as "slow" or slower than httpie.
If you've been working primarily with Javascript, for example, or even worse, Typescript, the question of "is this thing compiled or interpreted" is "yes". Compilation becomes a piece of either build tooling, where the artifact isn't a concrete binary, or even an attribute of runtime.
It really wouldn't be too hard to imagine a shop built on Javascript and Python, where compilation just doesn't factor into the system in a meaningful way.
Isn’t that answer applied to every programming language?
The "compiled vs interpreted" qualification was meant to preempt responses along the lines of "Of course it's faster -- it's compiled!"
I'm curious -- were the question simply "Is it faster?" how would you have responded?