Search code examples
pythonbeautifulsoup

How can I see the source code for a python library?


I currently find myself using the bs4/BeautifulSoup library a lot in python, and have recently been wondering how it works. I would love to see the source code for the library and don't know how. Does anyone know how to do this?


Solution

  • The first step is to ask the module itself. Usually its all you need

    >>> import bs4
    >>> bs4.__file__
    '/home/td/anaconda3/lib/python3.7/site-packages/bs4/__init__.py'
    >>> exit()
    $ pushd /home/td/anaconda3/lib/python3.7/site-packages/bs4
    $ ls
    builder    diagnose.py  __init__.py  testing.py
    dammit.py  element.py   __pycache__  tests