TubeCensus
A Python library for sampling YouTube channels and retrieving their historical Wayback Machine metadata.
Setup
- Requirements: ~20GB of storage.
- Defaults to
~/.tubecensus, but can be overriden byTubeCensus(data_dir=...), or theTUBECENSUS_DIRenvironment variable.
- Defaults to
pip install tubecensus- Example:
from tubecensus import TubeCensus
tc = TubeCensus() # client configuration goes here
sample = tc.sample(10, by='usernames') # sample 10 channels by their username field
subs = tc.fetch(sample, from_ts='2019', to_ts='2021') # retrieve the subs of those 10 when present from 2019-2021.
Features
sample(n, by={"usernames","ids","customs", "handles"})
- Sample YouTube channels from the URLs collected from the Wayback machine indices.
- Current version includes unique URLs up to 2023. These are featured in the four YouTube channel formats:
- Username (
/profile?user=,/user/): 34.8M channels - ID (
/channel/UC): 106M channels - Custom Page (
/c/): 5.9M channels - Handle (
/@): 25.4M channels
- Username (
- See our paper for more discussion.
sample_until(n, by, condition)
- Construct a conditional sample by repeatedly drawing channels and keeping them if the condition function is met.
- Can be used along with YouTube API / Innertube to construct samples conditioned on API metadata (e.g. country, join date, channel topic), or alternatively our metadata (subscribers at given timestamp).
fetch(channels, by, from_ts, to_ts, closest)
- Retrieve the subscriber counts for a given timestamp using the Wayback Machine.
- Requires to either specify a timestamp range using
(from_ts, to_ts)orclosest. - Returns outputs as a Pandas DataFrame, and includes additional channel identifier metadata extracted from the page (username / id fields).
Citation
@article{tubecensus,
title={TubeCensus: A Transparent, Replicable, and Large-Scale Census of YouTube Channels and their Subscriber Counts Over Time},
volume={20},
number={1},
journal={Proceedings of the International AAAI Conference on Web and Social Media},
author={Eggleston, Chloe and Handler, Abram and Pacheco, Maria Leonor},
year={2026},
month={May},
}
TO-DOs
- Early channel IDs via CDN URLs
- Before the standardization of the YouTube channel ID (c. 2012), they were occasionally used in the URLs of custom channel page content (such as profile pictures and custom CSS). They can be used to map additional usernames to channel IDs.
- Scrape channel hubs / related channels
- Subscriber counts for additional channels are sometimes accessible in the related channels tab. When paired with identifiers extracted from profile pictures or subscriber button HTML attributes, they can add upwards of ~10 subscriber counts in a given page scrape.
- Caching
- We redistribute the data collected in our paper as a part of our dataset, which is downloaded with this library. We plan to integrate these into the library such that URLs in the cache are not re-scraped.
Metadata
Release files for tubecensus 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tubecensus-1.0.2.tar.gz | 18.4 MB | Without provenance | Details for tubecensus-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tubecensus-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for tubecensus-1.0.2-py3-none-any.whl |
Total release size: 18.4 MB
Release files / tubecensus-1.0.2.tar.gz
| Download URL | tubecensus-1.0.2.tar.gz |
|---|---|
| Size | 18.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
617022824797670457240b79088107e5a374a30b147fed41cc88fb91fb967ab1
|
|
BLAKE2b-256 checksum How to use checksums |
7986626e2effd6f842a0359b65859a2cd809edb73f388eb872a77059f4618ae1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / tubecensus-1.0.2-py3-none-any.whl
| Download URL | tubecensus-1.0.2-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f99aa959b9de1b117acd9b91979ba03d49e2194b2b1c4ddd66ad219df3305271
|
|
BLAKE2b-256 checksum How to use checksums |
26606a43c566fa295e03f9ea94fdaad59e3889f8840586e1de71f54bcd8705ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for tubecensus 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.