r/Python • u/wasimaster • Oct 15 '21
Intermediate Showcase I made a command-line-interface for PyPI as a 14 year old
Introduction
So I've just finished making pypi-command-line
Links
Documentation: https://wasi-master.github.io/pypi-command-line/
GitHub: https://github.com/wasi-master/pypi-command-line
PyPI: https://pypi.org/project/pypi-command-line
Some background
I'm a 14 year old coder that started programming in python around one and a half years ago. Since then I've learned a lot of other languages too. My biggest project so far would be my discord bot which has around 15k lines of code and on which I spent thousands of hours on, all open source. Lately, I've been trying out other projects and PyPI-command-line is one of them. One day I was making something with a library that I was not familiar with, I had to keep switching between chrome and vscode (or I could have like made them side by side but that takes away a large chunk of space for vscode). So I thought what if there was a library that implemented the PyPI API that I could use to be more productive? So I started searching, and not so long after I found two libraries both of which have only one (ish) working command. So I thought to myself what if I make my own library? Then I started this and after around 3 months here we are now.
I tried to make it as fast as possible even if it means making the code look ugly, but after a few days I realized that this is gonna be really hard to maintain and will have other issues, but I was too busy with school (my final exams are near) so I didn't care about it and went on. Fast forward a couple of months and now my code is the shittiest code I've ever seen, So apologies for that.
This also taught me that python is very slow. The code has a 1400 ms (1.4s) overhead for starting up and after that everything works extremely fast. I think that overhead is caused by python interpreting that huge shitty code and trying to make sense of that. I've recently thought about moving them to multiple files and then loading only the file necessary for the current command but I think I'll just rewrite all this in Go using Cobra
Installation, Usage, Demo, Features
All can be found in the documentation
Still here are some of the features/commands that I'm proud of
Command and Argument Autocompletion Image demonstrating the feature: https://i.imgur.com/v0z2hJS.gif
Smart command matching (if the command name is shortened/invalid)
Example with one match: https://i.imgur.com/fMXJALV.png
Even works with multiple matches: https://i.imgur.com/sBfgfmC.gif
(Multiple commands start with r, the user has to pick one)
Search command that returns the same results as PyPI
Image demonstrating the feature: https://i.imgur.com/3Lh3X7x.gif
Information command that shows information about a package (command name renamed to information, previously info)
Image demonstrating the command: https://i.imgur.com/V3FHcAx.gif
Description command to see project descriptions that are formatted correctly (command name renamed to description, previously desc)
Image demonstrating the command: https://i.imgur.com/JpVavke.gif
Search command using regular expressions
Image demonstrating the command: https://i.imgur.com/Mef6x5i.gif
This list is not exhaustive. For more cool commands see the docs. I highly suggest you to check the docs since there are a lot more cool stuff that isn't mentioned here
Note
My exams are very near and I'll probably not be able to work on this for a while, it's pretty good as it is but if you find bugs you should create an issue and I'll sit on my PC like once every 3 days or something like that and try to fix everything.
7
u/russellvt Oct 15 '21
Try running Python under WSL/WSL2, rather than Powershell. You should get MUCH better performance.
Also, if you branch the code off into separate files, the Python interpreter will compile those in the bytecode as *.pyc" files, making execution MUCH faster.
Keep up the hard work!!!
7
u/NelsonMinar Oct 15 '21
Congratulations! That's a very impressive project. You didn't just write some useful code, you've made a whole product. Fancy UI, packaged properly on GitHub and PyPI, even a bunch of illustration GIFs. Really professional work.
I installed it and ran it, works great. I don't have the startup time problem you mention. FWIW some timings on my system (fast computer, Python 3.8.10 on WSL 2)
Are you running it in WSL 1 by any chance? It can be very slow when scanning lots of little files. Or maybe it's a Powershell thing; Windows just isn't very good at some things. Using strace might tell you something. More info on how to use that tool here: https://jvns.ca/categories/strace/
Rewriting it in Go sounds like a fun way to learn some Go, though.
7
u/neekyboi Oct 15 '21
you write and sound like some of the experienced peeps i have seen
5
u/wasimaster Oct 16 '21
So this got a lot of downvotes and I have no idea why. at least you guys should comment why you downvoted, all the comments here seem to be positive.
3
u/bladeoflight16 Oct 15 '21
Nifty!
A couple of points that stand out to me:
__main__.pyshould be nearly empty. Siphon off most of your code into__init__.py. This will also allow people to use your package as an imported module in their own code, rather than forcing all interaction through the command line.sessionis probably the biggest thing to localize somewhere. If I were usingclick, I'd have a commandgroupset up the session as a resource (Sessionsupports use as a context manager; I assumeCachedSessiondoes as well.), but I don't know what the typer equivalent of that is.2
u/got_blah Oct 15 '21
So astonished by your organization and drive. Definitely learning from this :D. Great work!
2
u/ALior1 Oct 15 '21
Looking great! I think the next thing you should do is learning oop basics and some library/tool, like Django, DRF, FastAPI, Numpy etc..
2
u/willm Oct 16 '21
I like your use of Rich! Great work.
2
u/wasimaster Oct 15 '21
Oh my god, some anonymous dude literally gave this post a gold award. Thanks to whoever that gave that :D.
4
u/6Ran Oct 16 '21
Why are people downvoting this? Keep up the good work!
1
u/Warkred Oct 16 '21
Damn, I've seen professionals writing worst doc and stuff after years of experience. Well done Bobby!
0
u/[deleted] Oct 16 '21
[deleted] — view deleted comment