238 points · by orf · 3y ago · 122 comments
1. Scanning of all new Python packages for accidentally published credentials
2. A browsable/searchable index of published code with a nice UI
3. Large-scale analysis of all published code to see how the language is evolving
Using this project anyone is able to download the contents of PyPI to their personal machine and analyse every piece of code ever published in a matter of hours.
I hope it enables people to do things with the worlds largest and oldest corpus of Python code that wasn't possible before, and while this is likely totally useless to most people I think that is kind of cool and unique.
This is one of the funniest things I've read all week.
For example, here is one service that is able to generate various canary tokens: https://www.canarytokens.org/generate
Or as another example, someone who wants to research how often people copy paste example config files without replacing things like credentials given in the example.
Probably a bunch of other reasons too.
So you found 57 live AWS keys[1]. That's out of 1631 according to your stats (If I didn't misread something). I wonder how many of the top two in the list are live :D
Google API Key 4,015 OpenAI API Key 3,531
[1] https://tomforb.es/i-scanned-every-package-on-pypi-and-found...
The project that leverages GitHub secret scanning found a lot more.
Incredibly there seems to be no sign yet of an S-curve type saturation (which would be only normal at this point of the Python hype cycle).
Would be interesting to control by repeating the analysis with other languages to see if that exponential growth is Python specific or really the exponential growth of all open source
Maybe publish in JOSS?
You could maybe parse the files and run a similarity function of some kind on class and method bodies, ignoring identifier names.
[1]: Rice's theorem https://en.wikipedia.org/wiki/Rice%27s_theorem
Like why not assign a character to each keyword: 'if' = 'i', 'while' = 'w', 'true' = 't', etc. Then reduce code to this, removing all whitespace comments and identifiers. so `if True: while True: pass` would become `itwtp`.
then the similarity is just an edit distance between two given strings?
Anyway, very cool. I am shocked at how many header files are present.
Another idea - how many unique files are there between releases and how many unique files are there total? Take a sha hash of every file, every commit. Calculate how many shas are shared between releases vs novel (ie # files churned per release). Can then also calculate on the global uniqueness over time. Of course, this means calculating billions of sha sums, so it could take forever, unless you had some cute trick to rip the value out of the git repos directly. Maybe you could even beat the odds and find that 1 in a quadrillion hash collision.
https://play.clickhouse.com/play?user=play#U0VMRUNUIHByb2plY...
Spoiler: the answer is nightly builds, huge binaries and a lot of wheels per release.
Example: https://play.clickhouse.com/play?user=play#U0VMRUNUIHByb2plY...
This is a nice dataset for exploration, although small (only one billion records). Going to upload all lines of code...
clickhouse-local --query "SELECT project_name, sum(lines), sum(size) FROM '*.parquet' WHERE skip_reason = '' AND project_name ILIKE '%ClickHouse%' GROUP BY project_name ORDER BY 2 DESC"
https://clickhouse.com/blog/extracting-converting-querying-l...Thanks so much for that!
I was looking into some browser duckdb WASM setup that reads the parquet files via http but I ran out of steam.
BTW RealPython is quite boring about wanting you to create an account, I'm sure they didn't use to be as bad but I can barely read that page in its entirety without getting forced to create an account.
> Not all files can be committed to GitHub ... very long lines ... VCS directories
Wait so github will reject a push if one of the commits contains a file with very long lines in it?
The “very long lines” exclusion is for text files that are very large but contain less than 5 or so lines. If I remember correctly there are some “py-armour” files that are basically just big dumps of base64 encoded python byte code on two or so lines.
These are likely unique files and so won’t compress well, which bloats the size of the repositories. If you’re interested you can use the SQL console on the datasets page to take a look at the specific files.
And github will block a push containing a commit which creates one of these files?
And git itself does not?
Github has a max size limit per repository. You can push a 150gb git repository to github: it won't stop you, but you'll get a message from support telling you remove it within 48 hours.
By "heuristically excluding some text files that won’t compress well based on their content and size before committing", we are able to keep the size bound of the repositories within those set by Github whilst keeping the majority of useful code.
We have excluded 26,610 .py files for being too large, whilst keeping 414,228,665 .py files. The average size for an excluded .py file is 15 MiB, vs ~10KiB for included files.
1. https://play.clickhouse.com/play?user=play#c2VsZWN0IHNraXBfc...
There is a search page where I can look up which repo a specific version of a specific PyPI package is in.
But I didn't find that index in the metadata files ("repositories_with_releases.json" seemed the most likely candidate).
Is it available as a flat file but I'm just too blind to see it?
The problem is that it’s pretty huge and would need to be an artefact. I’ll have a think.
Will Microsoft see this as a free license to use all of PyPI?
One can argue about ToS and copyright, about different interpretations of fair use, derivative work, DRM protections, and so on. Usually people are not interested to discuss finer details of those things. Most people seems to want to perceive it as either being public or not public, in which case, Youtube is just as public as PyPi.
It's a fallback clause, "fair use" is irrelevant if you've already given github permission to use it. By adding that clause you can no longer argue that it's not fair use to use the code you put on github after agreeing to their terms.
You can’t use a license to bind people who don't need a license.
Your reciprocity suggestion could also work, since it would mean any LLM trained on even a single file of GPL code would be "poisoned" in the sense that any code it produced would also be GPL. This would make people wary of using the LLM for writing code, and thus would make the creators of it wary of training it on the code.
Code which has a "can't be placed on github" license restriction is definitely not open source, regardless of what other terms the license purports to have.
Copilot was trained on Github code under a “training models doesn’t require permission” theory before there was anything about it in the ToS, and basically every other large model has taken a similar approach to publicly-accessible data of all kinds.
> Will Microsoft see this as a free license to use all of PyPI
Microsoft doesn’t think they need a license for model training.
This is a perfect job for task-spooler! :D
To mirror your pypi data, I sshed into my server and did this:
mkdir -p ~/src/github.com/pypi-data
cd !$
wget https://raw.githubusercontent.com/pypi-data/data/main/links/repositories.txt
xargs -L1 tsp git clone --bare < repositories.txt
And then I closed the ssh connection to my server, knowing that my server will proceed to mirror all of those repositories of yours one by one :D xargs -L1 -P20 git clone --bare < repositories.txt(Or you could also run your way in tmux or screen.)
With task-spooler, it puts all of the commands (in this case, the individual git clone commands for each of the repos) in a queue and it runs the commands independently of my ssh session, so I can quickly add a bunch of jobs like this to the queue and immediately disconnect my ssh session.
I’m working on distributing this data without GitHub - git packfiles are a fantastic way of compressing this data, and you can serve those easily enough from a bucket.
as a python oldie coming back into python, i've been surprised by dataclasses. are they basically "backwards compatible better classes"? any strong blogposts or readings that people can share about better typed python/OSS module publishing practices?
Dataclasses are nice - they are a pared down version of the attrs library, so a simple way to create data-only or mainly-data records through classes. They are not intended to replace all classes.
Also why no Azure alongside AWS and Google?
OpenAI is one of the supported platforms - A list of providers is at https://docs.github.com/en/code-security/secret-scanning/sec...
This analysis will be re-done with some other data soon.
>There are too many ways to do the same thing, (...)
Fair, but that's a funny statement to make because Python from the start tried to have just one obvious solution for every problem. Maybe that's just what happens with languages over time.
>not type safe
Nitpick: Python is dynamically typed, but is actually quite type safe as used in practice (i.e. type errors are usually caught in runtime instead of silently doing the wrong thing). YMMV of course.
>and I personally don't know many real python pros, the majority are just using python to play with.
The beautiful thing about Python is that you don't have to be a pro to use it effectively :). And I think this may be a result of your professional bubble - for example I don't know any Java pros, but I have no doubts there are many.