Skip to content

Language

This section contains the reference for the implementation of tokei's Language struct.

Language

Language() -> None

A struct representing statistics about a single Language.

References

tokei reference

Examples

>>> import pytokei
>>> lang = pytokei.Language()
>>> lang
Language(empty: true)
Note

mark_inaccurate is not defined, this may be better done from the rust side.

add_report

add_report(report: Report) -> int

Add a Report to the Language. This will not update the totals in the Language class.

blanks property

blanks() -> int

The total number of blank lines. tokei reference.

children property

children() -> dict[LanguageType, list[Report]]

A map of any languages found in the reports. tokei reference.

children_plain

children_plain() -> dict[str, list[dict[str, dict[str, int]]]]

The equivalent version of reports_plain method, but with children.

code property

code() -> int

The total number of lines of code. tokei reference.

comments property

comments() -> int

The total number of comments(both single, and multi-line). tokei reference.

files

files() -> int

Counts the number of reports.

innacurate property

innacurate() -> bool

Whether this language had problems with file parsing. tokei reference.

is_empty

is_empty() -> bool

Checks if the language is empty. Empty meaning it doesn't have any statistics.

lines

lines() -> int

Returns the total number of lines.

reports property

reports() -> list[Report]

A collection of statistics of individual files. tokei reference.

reports_plain

reports_plain() -> list[dict[str, dict[str, int]]]

A version of reports method but in plain python objects.

Instead of a list with reports, it returns a list with dicts containing as key the name of the file and a dict with each one of the reports's objects.

sort_by

sort_by(category: Sort) -> None

Sorts each of the Reports contained in the language based on what category is provided.

summarise

summarise() -> Language

Creates a new Language from self, which is a summarised version of the language that doesn't contain any children. It will count non-blank lines in child languages as code unless the child language is considered "literate" then it will be counted as comments.

total

total() -> None

Totals up the statistics of the Stat class currently contained in the language.