ExDoc
Documentation extractor.
Extracts pieces of documentation from your code to build a document which can be fed to template processors.
Output can be in JSON, YAML, whatever. Use any command-line templating engine, like j2cli, to render templates from it.
It does not do any automatic background magic: it just offers helpers which allows you to extract the necessary pieces.
Currently supports parsing the following documentation formats:
Collectors
ExDoc is just a set of helper functions that collects information into dictionaries.
Python
Helpers for Python objects
doc(obj, of_class=None)
Get parsed documentation for an object as a dict.
This includes arguments spec, as well as the parsed data from the docstring.
from exdoc import doc
The doc() function simply fetches documentation for an object, which can be
- Module
- Class
- Function or method
- Property
The resulting dictionary includes argument specification, as well as parsed docstring:
def f(a, b=1, *args):
''' Simple function
: param a: First
: type a: int
: param b: Second
: type b: int
: param args: More numbers
: returns: nothing interesting
: rtype: bool
: raises ValueError: hopeless condition
'''
from exdoc import doc
doc(f) # ->
{
'module': '__main__',
'name': 'f',
'qualname': 'f', # qualified name: e.g. <class>.<method>
'signature': 'f(a, b=1, *args)',
'qsignature': 'f(a, b=1, *args)', # qualified signature
'doc': 'Simple function',
'clsdoc': '', # doc from the class (used for constructors)
# Exceptions
'exc': [
{'doc': 'hopeless condition', 'name': 'ValueError'}
],
# Return value
'ret': {'doc': 'nothing interesting', 'type': 'bool'},
# Arguments
'args': [
{'doc': 'First', 'name': 'a', 'type': 'int'},
{'default': 1, 'doc': 'Second', 'name': 'b', 'type': 'int'},
{'doc': 'More numbers', 'name': '*args', 'type': None}
],
}
Note: in Python 3, when documenting a method of a class, pass the class to the doc() function as the second argument:
doc(cls.method, cls)
This is necessary because in Python3 methods are not bound like they used to. Now, they are just functions.
getmembers(obj, *predicates)
Return all the members of an object as a list of (key, value) tuples, sorted by name.
The optional list of predicates can be used to filter the members.
The default predicate drops members whose name starts with '_'. To disable it, pass None as the first predicate.
subclasses(cls, leaves=False)
List all subclasses of the given class, including itself.
If leaves=True, only returns classes which have no subclasses themselves.
SqlAlchemy
Documenting SqlAlchemy models.
from exdoc.sa import doc
doc(User) # ->
{
'name': 'User',
# List of tables the model uses
'table': ('users',),
'doc': 'User account',
# PK: tuple[str]
'primary': ('uid',),
# Unique keys
'unique': (
# tuple[str]
('login',),
),
# Foreign keys
'foreign': (
{'key': 'uid', 'target': 'users.uid', 'onupdate': None, 'ondelete': 'CASCADE'},
),
# Columns
'columns': [
{'key': 'uid', 'type': 'INTEGER NOT NULL', 'doc': ''},
{'key': 'login', 'type': 'VARCHAR NULL', 'doc': 'Login'},
{'key': 'creator_uid', 'type': 'INTEGER NULL', 'doc': 'Creator'},
{'key': 'meta', 'type': 'JSON NULL', 'doc': ''},
],
# Relationships
'relations': [
{'key': 'creator', 'model': 'User',
'target': 'User(creator_uid=uid)', 'doc': ''},
{'key': 'devices[]', 'model': 'Device',
'target': 'Device(uid)', 'doc': ''},
{'key': 'created[]', 'model': 'User',
'target': 'User(uid=creator_uid)', 'doc': ''},
]
}
Building
Create a python file that collects the necessary information and prints json:
#! /usr/bin/env python
from exdoc import doc
import json
from project import User
print json.dumps({
'user': doc(User),
})
And then use its output:
./collect.py | j2 --format=json README.md.j2
Metadata
Release files for exdoc 0.1.4.post1
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 | |
|---|---|---|---|---|
| exdoc-0.1.4.post1.tar.gz | 14.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| exdoc-0.1.4.post1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 28.5 kB
Release files / exdoc-0.1.4.post1.tar.gz
| Download URL | exdoc-0.1.4.post1.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f5c1baa9dfc44ffc303120e636a95e10b1296298d95f05b98e922bb995f93a6
|
|
BLAKE2b-256 checksum How to use checksums |
9133c0b11500df42b7d312bf4ef2efe15f73cbd6b89387eaa8f2b0e75b8e8340
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.4.2 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.6
|
Release files / exdoc-0.1.4.post1-py2.py3-none-any.whl
| Download URL | exdoc-0.1.4.post1-py2.py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1ca500b965bc943c47b01460ebd9a6982845cb20eb71fcc00f610548fce1e266
|
|
BLAKE2b-256 checksum How to use checksums |
69dc5b84a7b8c6574c2d2f2cf8280ad9efdfa37bee397811a2a55c57211941e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.4.2 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.6
|
Security for exdoc 0.1.4.post1
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.