Skip to content

Stats

This section contains the reference for the implementation of tokei's CodeStats and Report structs.

CodeStats

CodeStats() -> None

A class representing stats about a single blob of code. tokei reference.

Examples

>>> from pytokei import CodeStats
>>> CodeStats()
CodeStats(blanks: 0, code: 0, comments: 0, lines: 0)

blanks property

blanks() -> int

The blank lines in the blob. tokei reference

blobs property

blobs() -> dict[LanguageType, CodeStats]

Language blobs that were contained inside this blob, represented in the equivalent python objects. tokei reference

blobs_plain property

blobs_plain() -> dict[str, dict[str, int]]

Equivalent method to blobs but in builtin python objects.

code property

code() -> int

The lines of code in the blob. tokei reference

comments property

comments() -> int

The lines of comments in the blob. tokei reference

lines

lines() -> int

Get the total lines in a blob of code.

plain

plain() -> dict[str, int]

Returns the content of the blob as a dict, blanks, code, comments and lines.

summarise

summarise() -> CodeStats

Creates a new CodeStats from an existing one with all of the child blobs merged.

Report

Report() -> None

A struct representing the statistics of a file.

tokei reference.

It can be constructed easily:

Examples

>>> from pytokei import Report
>>> Report("filename")
Report("filename")

But it isn't expected to be used like this, just get it from a parsed directory.

name property

name(str) -> str

Filename that represents.

plain

plain() -> dict[str, dict[str, int]]

Representation of the object in builtin python objects, where the key corresponds to the filename that generated it, and the value is the result of CodeStats.plain method.

stats property

stats(str) -> CodeStats

The code statistics found in the file.