Skip to main content

The Bibliotheca Anonoma’s complete Python Wrapper for the 4chan API. Uses requests, respects if-modified-since headers on updating threads. Caches thread objects. Fun stuff.

An absolute must if you want to interface with or scrape from 4chan, using a Python script.

Hosted Documentation

Github Repository

You can install this library straight from PyPi with:

pip install basc-py4chan

Getting Help

If you want help, or you have some trouble using this library, our primary IRC channel is #bibanon on irc.rizon.net. Simply head in there and talk to dan or antonizoon. Otherwise, you can put a issue on our Github Issue Tracker and we’ll respond as soon as we can!


Originally written by Edgeworth, the library has been adopted and extended by Bibliotheca Anonoma.

Note: If you’re a developer that still uses Edgeworth’s py-4chan, and don’t want to change the function names, Bibliotheca Anonoma maintains an up-to-date, API-compatible version of py-4chan here.

Usage

import basc_py4chan
b = basc_py4chan.Board('b')
thread = b.get_thread(423491034)

print(thread)

for file in thread.files():
    print(file)

# In a while...
print("I fetched", thread.update(), "new replies.")

Documentation is located here.

Extending this Library

There are a wealth of other imageboard APIs that have adopted a similar structure to the 4chan API (such as 8chan/vichan, or 420chan). FoolFuuka also has an API which differs significantly from them since it predates them, but it can be made to fit.

So instead of writing a whole new class from scratch, you could inherit and override BASC-py4chan to support them. This would also allow the BASC-Archiver to possibly make it work. Here’s how:

import basc_py4chan

class URL (basc_py4chan.URL):
    # see BASC-py4chan's `url.py` for an example of how to set up
    # the URLs.
    def __init__(self, https=False):
        # Your API URL Subdomains
        DOMAIN = { }

        # Your API URL Templates
        TEMPLATE = { }

        # Your API Listings
        LISTING = { }

        # combine all dictionaries into self.URL dictionary
        self.URL = TEMPLATE
        self.URL.update({'domain': DOMAIN})
        self.URL.update({'listing': LISTING})

class Board(basc_py4chan.Board):
    # add your own overrides here, or leave it alone
    pass

class Thread(basc_py4chan.Threads):
    # add your own overrides here, or leave it alone
    pass

class Post(basc_py4chan.Post):
    # add your own overrides here, or leave it alone
    pass

# note that all classes must be in one file (we recommend
#   py?chan/__init__.py ), due to how python modules work

From there, just override any methods in classes Board, Thread or Post as necessary.

Notice that if your imageboard’s API does not support a certain feature in the 4chan API, you should have the function raise an AttributeError.

License

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                   Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

 0. You just DO WHAT THE FUCK YOU WANT TO.

Release files for BASC-py4chan 0.6.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BASC-py4chan 0.6.6
File Size Uploaded
BASC-py4chan-0.6.6.tar.gz 11.8 kB Details

Release files / BASC-py4chan-0.6.6.tar.gz

Download URL BASC-py4chan-0.6.6.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
719769f993db79c57036a5ef68519e52a2ba849f9d03cac29f6e860ed8593b6c
BLAKE2b-256 checksum
How to use checksums
017304390d6006ebe903d06980a37c3d2e4a977b923ed924067e20ff2e804bd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.10.2

Release history Release notifications | RSS feed

This release

0.6.6 This release

1 release file

0.6.5

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.2

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