Depending on what you mean by attribute - you just want to extract the #docstrings?
On class (and class instances) and function/method objects, it's available as `<obj>.__doc__`. Same for modules. That covers most types of objects...
If you mean extracting information from type annotations, there's an inspection interface for that, too.
Ah - you mean something like a *data* attribute on a class, like:
class Foo:
"sorta-docstring comment before"
a = 6
"sorta-docstring comment after"
foo = Foo()
Then `foo.a.__doc__` gives you the docstring for the int class/function, where you want to extract a comment that's before or after it instead?
If so, then the AST is the way, but I'm afraid I don't personally know of a PyPI package that already exists to do it.
Sorry.