Skip to main content

iceberg

CI PyPI License: MIT Python 3.14+

The public API is the tip of the iceberg. iceberg marks the waterline.

iceberg inspects the public API of a Python package and makes a snapshot of it. It reads the source with the Python ast module. It never imports or runs your code, and it has no runtime dependencies.

Features

  • It shows each public module, class, function and assignment. It shows full signatures (parameter names, annotations and default values), the bases and keyword arguments of a class (class Error(Base, metaclass=Meta)), and the members of a class.
  • It includes definitions in if and try blocks at module level or in a class body. Examples are if TYPE_CHECKING:, version checks and except ImportError: fallbacks. If a name has more than one definition, iceberg keeps the first one.
  • If a module has __all__, iceberg uses it as the list of public names. If the module has no __all__, a name is public when it does not start with an underscore.
  • iceberg reads __all__, but it does not run the code. It understands these forms: literal lists and tuples, + concatenation, +=, .extend(), .append(), .insert(), .remove(), .sort() and .reverse(). It also understands sub.__all__ and from .sub import __all__ for modules in the analyzed tree.
  • iceberg applies the changes to __all__ in module-level if and try blocks. __all__ keeps each name that a branch adds.
  • If iceberg cannot read __all__, it shows a warning with the file and the line. Then it uses the underscore rule.
  • Dunder class members such as __call__ and __eq__ are public. Members with the names _x and __x (name-mangled) are private.
  • iceberg follows re-exports through __init__.py. It understands relative imports, absolute imports, namespace packages, and imports in try and if blocks.
  • A star import (from ._core import *) from a module in the analyzed tree gives the __all__ of that module. If that module has no __all__, it gives the public names of the module.
  • iceberg never removes a public name silently. Sometimes iceberg cannot find the definition of a public name, for example from math import sqrt in __all__. Then iceberg shows the name as a reference.
  • iceberg gives a tree output for people and a 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 can be a package directory, a directory that contains packages (such as src/ or a namespace package), or one .py file. iceberg gives names to packages from the path that you give it. For example, iceberg src/sheridan shows sheridan.iceberg, and iceberg src/sheridan/iceberg shows iceberg.

The exit codes are:

  • 0: The command was successful.
  • 1: An iceberg error occurred. Examples are a path that does not exist, an incorrect configuration, a source file that iceberg cannot read or parse, and an --output file that iceberg cannot write.
  • 2: An unexpected error occurred.

An unexpected error is a bug in iceberg. To report it, do these steps:

  1. Run the command again with --traceback (or set ICEBERG_DEBUG=1).
  2. Copy the full traceback.
  3. Put the traceback in your bug report.

iceberg decodes source files in the same way as Python. The encoding is UTF-8, unless a PEP 263 encoding declaration such as # -*- coding: latin-1 -*- gives a different encoding.

iceberg writes the report to stdout as UTF-8. The encoding of the console or the pipe has no effect. Thus, the tree connectors do not cause an error on Windows.

-o/--output PATH writes the report to PATH as UTF-8 with a final newline. The encoding of the console has no effect. iceberg writes to a temporary file first. When the report is complete, iceberg moves the file into PATH. Thus, an error never leaves a partial file and never overwrites the old file.

  • If PATH is a symlink, iceberg writes the report to the target file of the link. The link does not change.
  • If the file exists, it keeps its permission bits. After iceberg writes the file, the user who ran iceberg owns it.
  • If PATH is not a regular file (for example /dev/stdout or a named pipe), iceberg writes to it directly, without a temporary file.

Continue after bad files

By default, if iceberg cannot read or parse a file, the run stops. An example is a vendored Python 2 module. With --keep-going, iceberg does these steps:

  1. It skips the bad module.
  2. It prints the API of all the other modules.
  3. It writes one diagnostic on each line to stderr. First, it writes an error for each module that it skipped. Then it writes a warning for each exported name that no import binds. The tree marks these names (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

If iceberg skipped a module, the exit code is 1. If there are only warnings, the exit code is 0. With --json, the output also has a top-level diagnostics list. The paths in this list are relative to the analyzed directory. If you give one .py file and iceberg cannot parse it, iceberg shows an error. There is nothing else to show.

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

The definitions come first. Then come the public names that iceberg cannot connect to a definition. iceberg shows the import that binds each of these names. If no import binds a name, iceberg marks it (unresolved). In this example, a module-level __getattr__ supplies the name.

If the __init__.py of a package defines __all__, iceberg moves the exported names up to the package level. It does not show the private submodules. If there is no __all__, iceberg shows each public module:

$ 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. This integer changes when a change to the JSON format can break the programs that read it.

Each package, module, class, function, assignment and reference object has a node_type field. Its value is package, module, class, function, assignment or reference. Function objects also have a kind field. Its value is 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 each case against this schema.

The cases/ directory shows each supported layout and edge case, with 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. If you give it one file, it returns a Module. A Package is a trie of modules and subpackages. Its assignments, classes, functions and references properties give the package-level (__init__.py) API.

All models are frozen dataclasses: Package, Module, Class, Function, Parameter, Assignment and Reference.

  • Function.kind tells the difference between a module-level "function" and a "method", "classmethod", "staticmethod" or "property" of a class.
  • Function.decorators lists the decorators of a function as source strings.
  • Class.bases and Class.keywords list the bases and the keyword arguments of a class as source strings. An example of a keyword argument is metaclass=ABCMeta.

The tree shows a property as the attribute that callers read (property p: int). It puts the kind before the names of classmethods and staticmethods. It does not show property setters and deleters as separate items.

A function with typing.overload signatures is one Function. Its overloads tuple holds those signatures. The tree shows one line for each overload. It does not show the signature of the implementation, unless you give --show-overload-implementations.

get_public_api_report(path, keep_going=True) does the same work as --keep-going in Python code. It returns a Report with these attributes:

  • api: the Package or the Module.
  • diagnostics: a tuple of Diagnostic objects. Each object has a severity, a module, a path, a message and a lineno.
  • has_errors: True if iceberg skipped a module.

Without keep_going, the function raises an exception at the first bad file, the same as get_public_api. But it still lists the warnings for unresolved names.

load_json reads the output of iceberg --json back into a Package or Module. The JSON keeps package paths relative to the analyzed directory. Thus, the paths that load_json gives are also relative, unless you give root=. load_json raises SnapshotError (an IcebergError) for these problems:

  • The JSON is not valid.
  • There is no schema_version, or iceberg does not support it.
  • A node has an incorrect structure.
from pathlib import Path

from sheridan.iceberg import load_json

old = load_json(Path("api.json").read_text(encoding="utf-8"))

sheridan.iceberg.utilities has functions that make the same models from smaller inputs: get_function, get_class, get_assignment, get_module and get_package. These functions accept source strings, AST nodes, paths or live objects. If you give a path, get_function and get_class look for name in the module-level definitions first. To select a nested definition, use a dotted name such as "MyClass.method".

When iceberg walks through a directory, it skips these directories and files:

  • Hidden directories and __pycache__.
  • Usual directories that do not contain source: build, dist, venv, env, node_modules, site-packages and *.egg-info.
  • A directory or .py file that you cannot import, because its name is not a Python identifier or is a keyword. Examples are my-dir/ and my-script.py.

iceberg always analyzes the directory that you give it, even if its name is not an identifier.

To skip more paths, give --exclude one or more times, or set exclude in the configuration (see below). Each value is a glob. iceberg compares it with the path of each directory and file, relative to the directory that you give. ** matches zero or more directories:

iceberg src/mypkg --exclude legacy --exclude '**/*_pb2.py'

--exclude adds to the exclude list from the configuration file.

Configuration

iceberg starts at the analyzed path and goes up through the parent directories. It examines each directory, the nearest one first:

  • If the directory has an .iceberg.toml file, iceberg uses it. In one directory, .iceberg.toml has priority over pyproject.toml.
  • If the directory has no .iceberg.toml but has a pyproject.toml, this directory is the project root. The search stops there. iceberg uses the [tool.iceberg] table of the file. If there is no table, iceberg uses the default values.
  • iceberg never uses configuration above the project root. Examples are a ~/.iceberg.toml file or the pyproject.toml of a parent project.
  • If iceberg finds no file, it uses the default values.

iceberg does not accept unknown keys.

These command-line options change the configuration for one run:

  • --config PATH reads only PATH and does not search. If the name of the file is pyproject.toml, iceberg reads its [tool.iceberg] table. iceberg reads all other files in the same way as an .iceberg.toml file.
  • --no-config ignores all configuration files and uses the default values. You cannot use it together with --config.
  • --max-workers N replaces max_workers, and --exclude adds to exclude. Values from the command line always have priority 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 use a configuration without a file, give 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

For more information, see CONTRIBUTING.md.

Metadata

Release files for sheridan-iceberg 8.0.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 sheridan-iceberg 8.0.6
File Size Uploaded Provenance Actions
sheridan_iceberg-8.0.6.tar.gz 113.9 kB With provenance Details for sheridan_iceberg-8.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sheridan-iceberg 8.0.6
File Interpreter ABI Platform Actions
sheridan_iceberg-8.0.6-py3-none-any.whl Python 3 none any Details for sheridan_iceberg-8.0.6-py3-none-any.whl

Total release size: 177.2 kB

Release files / sheridan_iceberg-8.0.6.tar.gz

Download URL sheridan_iceberg-8.0.6.tar.gz
Size 113.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f3238b0385d0b00ac0be0e94287e75610bd80c63c766faaf7bb5a0e620318611
BLAKE2b-256 checksum
How to use checksums
c6ddbb3c7572010ae151bc6716f849c4fa9b3247c46904063ff529b0c6ca4399
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 10, 2026.

Transparency log

Release files / sheridan_iceberg-8.0.6-py3-none-any.whl

Download URL sheridan_iceberg-8.0.6-py3-none-any.whl
Size 63.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96fab4413eed2fd5cf4ab6dfcb840606f5bd4b91e2b3209f13baed9b7b3ddf9f
BLAKE2b-256 checksum
How to use checksums
237915370e7a9e3a6ae2c8bf5dad8fbfb8477a41478bb620c552599ec6ffa5ea
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 10, 2026.

Transparency log

Security for sheridan-iceberg 8.0.6

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.

Select from 2 files

Attestation for sheridan_iceberg-8.0.6.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 10, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

8.0.6 This release

2 release files Full provenance

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