Skip to main content

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 by TubeCensus(data_dir=...), or the TUBECENSUS_DIR environment variable.
  • 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:
    1. Username (/profile?user=, /user/): 34.8M channels
    2. ID (/channel/UC): 106M channels
    3. Custom Page (/c/): 5.9M channels
    4. Handle (/@): 25.4M channels
  • 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) or closest.
  • 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)

Source distribution for tubecensus 1.0.2
File Size Uploaded
tubecensus-1.0.2.tar.gz 18.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for tubecensus 1.0.2
File Interpreter ABI Platform
tubecensus-1.0.2-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page