Skip to content

Languages

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

Languages

Languages() -> None

A class representing a list of languages counted in the provided directory. See LanguageType.list

Examples

```python
>>> from pytokei import Languages
>>> langs = Languages()
>>> langs
Languages()
```

References

Languages implementation

__getitem__

__getitem__(lang_type: LanguageType) -> Language | ValueError

Implements the same functionality as in tokei to access the contents of a given languages object by a key.

Corresponds to let rust = &languages[&LanguageType::Rust]; in python

files

files() -> dict[str, int]

Total number of files in the value, corresponding to the language name key.

get_languages

get_languages() -> dict[LanguageType, Language]

Exposes the inner struct from rust to the classes defined in python.

get_languages_plain

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

The same method as get_languages but in python builtin objects.

get_statistics

get_statistics(paths: list[str], ignored: list[str], config: Config) -> None

Populates the Languages struct with statistics about languages provided by Language.

Takes a list of of paths (as str) to recursively traverse, paths can be relative, absolute or glob paths. A second list of paths (as str) to ignore, these strings use the .gitignore syntax, such as target or **/*.bk.

Parameters
paths : list[str]
    List of files to traverse. It may be a single directory.
ignored : list[str]
    List of files to ignore. If you don't want anything ignored, just pass `["ignored"]`.
config : Config
    Config instance. If you dont have any preferences, just pass `Config`.

language_names

language_names() -> Optional[list[str]]

Returns the list of language names, if any was found.

report_compact_plain

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

Returns the information as the default command from tokei. Computes the statistics per language.

total

total() -> Language

Summary of the Languages struct.

total_plain

total_plain() -> dict[str, int]

Returns the content of total as a dict.