iceberg
The public API is the tip of the iceberg.
icebergmarks the waterline.
iceberg inspects and snapshots the public API surface of a Python package.
It reads source with Python's ast module and never imports or executes your
code, and it has no runtime dependencies.
Features
- Reports every public module, class, function, and assignment, with full
signatures (parameter names, annotations, defaults), class bases and
keyword arguments (
class Error(Base, metaclass=Meta)), and class members. Definitions insideif/tryblocks at module level or in a class body (if TYPE_CHECKING:, version checks,except ImportError:fallbacks) count; when a name is defined more than once, the first definition is kept. - Uses
__all__as the source of truth when present and falls back to underscore-prefix inference when it is absent.__all__is evaluated statically: literal lists and tuples,+concatenation,+=,.extend(),.append(),.insert(),.remove(),.sort(),.reverse(), andsub.__all__orfrom .sub import __all__for modules inside the analyzed tree. Changes inside module-levelif/tryblocks are applied, and__all__keeps every name that any branch adds. When it cannot be evaluated, iceberg emits a warning naming the file and line, then falls back to inference. Dunder class members such as__call__and__eq__are public;_xand name-mangled__xare private. - Resolves re-exports through
__init__.py, including relative imports, absolute imports, namespace packages, and imports insidetry/ifblocks. A star import (from ._core import *) from a module in the analyzed tree binds that module's__all__, or its public names when it has none. - Never drops a public name silently: anything it cannot resolve to a
definition (e.g.
from math import sqrtlisted in__all__) is reported as a reference. - Human-readable tree output and deterministic JSON output.
Installation
pip install sheridan-iceberg
CLI
iceberg src/mypkg # tree output
iceberg src/mypkg --json # machine-readable output
iceberg src/mypkg --json -o api.json # write UTF-8 to a file instead of stdout
iceberg src/mypkg --show-overload-implementations # also show @overload implementations
iceberg src/mypkg --keep-going # skip files that cannot be read or parsed
iceberg src/mypkg --traceback # print the full traceback of an unexpected error
iceberg --version # print the installed version
python -m sheridan.iceberg src/mypkg
The path may be a package directory, a directory containing packages (such as
src/ or a namespace package), or a single .py file. iceberg names packages
after the path it is given: iceberg src/sheridan reports sheridan.iceberg,
while iceberg src/sheridan/iceberg reports iceberg.
Exit codes: 0 on success, 1 for iceberg errors (missing path, invalid
config, unreadable or unparseable source, unwritable --output file), 2 for unexpected errors.
An unexpected error is a bug in iceberg: run again with --traceback (or set
ICEBERG_DEBUG=1) to print the full traceback, and include it when you
report the bug. Source files
are decoded the way Python decodes them: UTF-8 unless a PEP 263 encoding
declaration such as # -*- coding: latin-1 -*- says otherwise.
-o/--output PATH writes the report to PATH as UTF-8 with a final newline,
whatever the console encoding. iceberg writes to a temporary file and moves it
into place only when the report is complete, so an error never leaves a partial
file or overwrites the previous one.
Keep going past bad files
By default, one file that cannot be read or parsed (for example a vendored
Python 2 module) stops the run. With --keep-going, iceberg skips that module,
prints the API of everything else, and writes one diagnostic per line to
stderr: an error for each skipped module, then a warning for each exported
name that no import binds (the names the tree marks (unresolved)):
/src/mypkg/vendored.py:2: error: Missing parentheses in call to 'print'. Did you mean print(...)?
/src/mypkg/__init__.py: warning: 'lazy_thing' is exported but never bound
The exit code is 1 when a module was skipped and 0 when there are only
warnings. With --json, the diagnostics are also in a top-level diagnostics
list, with paths relative to the analyzed directory. A single .py file that
cannot be parsed is still an error, since there is nothing else to report.
Example output
$ iceberg cases/case_11
package case_11
├── def area(radius: float) -> float
├── from collections import OrderedDict as Ordered
├── import json
├── lazy_thing (unresolved)
└── from math import sqrt
Definitions come first. Public names that iceberg could not resolve to a
definition follow, shown as the import that binds them. A name with no binding
import at all (here, one served by a module-level __getattr__) is marked
(unresolved).
When a package's __init__.py defines __all__, its exports are hoisted to
the package level and private submodules are hidden. Without __all__, every
public module is listed:
$ iceberg cases/case_09
package case_09
├── module case_09.alpha
│ ├── def add(x: int, y: int) -> int
│ └── def subtract(x: int, y: int) -> int
├── module case_09.beta
│ └── class Counter
│ ├── def __init__(self, start: int = 0) -> None
│ ├── def increment(self) -> None
│ └── def value(self) -> int
└── module case_09.gamma
├── VERSION: str
└── MAX_RETRIES: int
JSON output
--json prints one object for the analyzed package or module. Its first key is
schema_version, an integer that changes when the JSON format changes in a way
that can break consumers. Every package, module, class, function, assignment
and reference object has a node_type field (package, module, class,
function, assignment or reference). Function objects also have a kind
field (function, method, classmethod, staticmethod or property).
docs/schema/iceberg.schema.json is a JSON
Schema (draft 2020-12) for this output. The tests validate the output of every
case against it.
The cases/ directory documents each supported layout and edge case
alongside its expected output.
Programmatic use
from pathlib import Path
from sheridan.iceberg import get_public_api
api = get_public_api(Path("src/mypkg"))
for function in api.functions:
print(function.name)
get_public_api returns a Package (or a Module when given a single file).
A Package is a trie of modules and subpackages; its assignments,
classes, functions, and references properties expose the package-level
(__init__.py) surface. All models are frozen dataclasses: Package,
Module, Class, Function, Parameter, Assignment, and Reference.
Function.kind tells a module-level "function" apart from a class's
"method", "classmethod", "staticmethod" and "property", and
Function.decorators lists its decorators as source strings. Class.bases
and Class.keywords list a class's bases and keyword arguments such as
metaclass=ABCMeta as source strings. The tree shows a
property as the attribute callers read (property p: int) and prefixes
classmethods and staticmethods with their kind. Property setters and deleters
are not listed separately. A function with typing.overload signatures is one
Function whose overloads tuple holds those signatures. The tree shows one
line per overload and hides the implementation signature unless you pass
--show-overload-implementations.
get_public_api_report(path, keep_going=True) is the programmatic form of
--keep-going. It returns a Report whose api is the Package or Module
and whose diagnostics is a tuple of Diagnostic objects (severity,
module, path, message and lineno). Report.has_errors is True when a
module was skipped. Without keep_going, it raises on the first bad file like
get_public_api, but still lists the unresolved-name warnings.
load_json reads the output of iceberg --json back into a Package or
Module. The JSON stores package paths relative to the analyzed directory, so
the loaded paths are relative too unless you pass root=. It raises
SnapshotError (an IcebergError) for invalid JSON, a missing or unsupported
schema_version, and malformed nodes:
from pathlib import Path
from sheridan.iceberg import load_json
old = load_json(Path("api.json").read_text(encoding="utf-8"))
sheridan.iceberg.utilities provides helpers for building the same models from
smaller inputs: get_function, get_class, get_assignment, get_module, and
get_package accept source strings, AST nodes, paths, or live objects.
With a path, get_function and get_class look up name among module-level
definitions first. Use a dotted name such as "MyClass.method" to select a
nested definition.
When it walks a directory, iceberg skips hidden directories, __pycache__,
common non-source directories (build, dist, venv, env, node_modules,
site-packages and *.egg-info), and any directory or .py file whose name
cannot be imported because it is not a Python identifier or is a keyword (for
example my-dir/ or my-script.py). The directory you pass is always
analyzed, even if its own name is not an identifier.
To skip more paths, pass --exclude one or more times, or set exclude in the
configuration (see below). Each value is a glob matched against the path of a
directory or file relative to the directory you pass. ** matches any number
of directories:
iceberg src/mypkg --exclude legacy --exclude '**/*_pb2.py'
--exclude adds to the exclude list from the configuration file.
Configuration
iceberg walks up from the analyzed path and checks each directory, nearest first:
- If the directory has an
.iceberg.toml, iceberg uses it. In one directory,.iceberg.tomlhas priority overpyproject.toml. - Otherwise, if the directory has a
pyproject.toml, it is the project root and the search stops there. iceberg uses its[tool.iceberg]table, or the defaults if it has none. Configuration above the project root (for example a~/.iceberg.tomlor a parent project'spyproject.toml) never applies. - If no file is found, iceberg uses the defaults.
Unknown keys are rejected.
Command-line options change this for one run:
--config PATHreads onlyPATHand skips the search. A file namedpyproject.tomlis read from its[tool.iceberg]table; any other file is read like an.iceberg.toml.--no-configignores all configuration files and uses the defaults. It cannot be combined with--config.--max-workers Noverridesmax_workers, and--excludeadds toexclude. Command-line values always take precedence over the file.
iceberg src/mypkg --config ci/iceberg.toml --max-workers 4
iceberg src/mypkg --no-config
[tool.iceberg]
# Regex searched in each file's POSIX path relative to the analyzed directory's
# parent (for example `pkg/sub/mod.py`); matching files are skipped.
test_module_pattern = '(^|/)tests?(/|$)|(^|/)test_[^/]*\.py$|_test\.py$'
# Worker processes used to parse modules (default: 1, in-process). Only very
# large trees benefit; values above 1 require scripts calling get_public_api
# to be guarded by `if __name__ == "__main__":`.
max_workers = 1
# Globs matched against each directory's and file's path relative to the
# analyzed directory; matches are skipped. `**` matches any number of
# directories. The --exclude CLI option adds to this list.
exclude = ["legacy", "**/*_pb2.py"]
To bypass file discovery, pass a Config directly:
import re
from pathlib import Path
from sheridan.iceberg import Config, get_public_api
api = get_public_api(Path("src/mypkg"), config=Config(test_module_pattern=re.compile(r"_test\.py$")))
Development
task install # set up the environment
uv run prek install # install the Git hooks
task ci # lint, format check, type check, tests
See CONTRIBUTING.md for details.
Metadata
Release files for sheridan-iceberg 8.0.2
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 | Actions |
|---|---|---|---|---|
| sheridan_iceberg-8.0.2.tar.gz | 110.8 kB | With provenance | Details for sheridan_iceberg-8.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sheridan_iceberg-8.0.2-py3-none-any.whl | Python 3 | none | any | Details for sheridan_iceberg-8.0.2-py3-none-any.whl |
Total release size: 173.1 kB
Release files / sheridan_iceberg-8.0.2.tar.gz
| Download URL | sheridan_iceberg-8.0.2.tar.gz |
|---|---|
| Size | 110.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
162ea3f68daa7ca734bcb5b4fcd9b4298ee1f53ea53808e9469bef94198c06b7
|
|
BLAKE2b-256 checksum How to use checksums |
5c4825ba407e0ec76f2dcad789e51b9e3ad1a2f991b0519e489f8318975a346f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logRelease files / sheridan_iceberg-8.0.2-py3-none-any.whl
| Download URL | sheridan_iceberg-8.0.2-py3-none-any.whl |
|---|---|
| Size | 62.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61519e02fb43e31a20a7bd6fa3a79674cb42b92055f9b00cef34dc6c36631bc3
|
|
BLAKE2b-256 checksum How to use checksums |
374c98df59e759fdb8cbfd590db9fbaede9d1e9863bd048f7670027cebe532e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logSecurity for sheridan-iceberg 8.0.2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sheridan_iceberg-8.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logA 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.