Skip to main content

Python bindings to tokei, the Rust library to count code quickly.

Project description

pytokei


Pytokei is a python binding to tokei:

Tokei is a program that displays statistics about your code. Tokei will show the number of files, total lines within those files and code, comments, and blanks grouped by language.


This wrapper allows to obtain the same reports directly from python.

$ python
>>> import pytokei
>>> from rich import print
>>> langs = pytokei.Languages()
>>> langs.get_statistics(["."], ["tests/data", "requirements"], pytokei.Config())
>>> print(langs.report_compact_plain())
{
    'YAML': {'blanks': 6, 'code': 63, 'comments': 0, 'files': 1, 'lines': 69},
    'Python': {'lines': 376, 'blanks': 89, 'files': 2, 'code': 280, 'comments': 7},
    'Makefile': {'code': 18, 'lines': 26, 'comments': 0, 'blanks': 8, 'files': 1},
    'Markdown': {'code': 0, 'blanks': 37, 'files': 10, 'comments': 52, 'lines': 89},
    'Rust': {'blanks': 23, 'comments': 23, 'code': 317, 'lines': 363, 'files': 7},
    'TOML': {'code': 14, 'comments': 2, 'lines': 20, 'blanks': 4, 'files': 2}
}

It includes a small CLI for simple use cases (run against the pytokei's folder):

$ pytokei pytokei
                        pytokei                         
┏━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━┓
┃ language   ┃ Files ┃ Lines ┃ Code ┃ Comments ┃ Blanks ┃
┡━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━┩
│ Rust       │     9 │  1011 │  846 │       49 │    116 │
│ Python     │     5 │   568 │  436 │       13 │    119 │
│ Markdown   │    11 │   423 │  123 │      179 │    121 │
│ Plain Text │     4 │   133 │    0 │      133 │      0 │
│ TOML       │     3 │    75 │   59 │        6 │     10 │
│ YAML       │     1 │    69 │   63 │        0 │      6 │
│ Makefile   │     1 │    26 │   18 │        0 │      8 │
│ Dockerfile │     1 │    16 │    7 │        3 │      6 │
│ Shell      │     3 │    12 │   12 │        0 │      0 │
│ Autoconf   │     3 │     7 │    7 │        0 │      0 │
└────────────┴───────┴───────┴──────┴──────────┴────────┘

For more information about tokei, please visit the original repo.

PyPI pyversions example workflow license

Installation

pip install pytokei

Requires Python >= 3.7.

Binaries are available for:

  • Linux: x86_64, aarch64, i686, armv7l, musl-x86_64 & musl-aarch64
  • MacOS: x86_64 & arm64 (except python 3.7)
  • Windows: amd64 & win32

Otherwise, you can install from source which requires Rust stable to be installed.

Why this library?

Wanted to practice rust, and taking this library to python seemed like a good opportunity. It's awesome, and maybe more people coming from python will find something useful to do with it.

But really? Just for fun :)

Documentation

What times should you expect?

Running Languages.get_statistics against cpython takes a little less than 200 milliseconds.

Some more info should be found in the docs.

Development

You will need:

  • maturin to compile the library

  • maturin develop / make develop to compile the code.

From python side:

Run make install-dev inside a virtual environment, make test, make mypy and make format to ensure everything is as expected, and make docs to build the documentation.

There are some problems when building the docs with mkdocstrings, a reminder is in the following github issue. For the moment, it seems that the best option is to remove the .so file and build the docs without it.

To create a new release:

  • Update the version in Cargo.toml.
  • Create a new tag to run the github action workflow.
  • git push --atomic origin main tag-name

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytokei-0.2.0.tar.gz (195.7 kB view details)

Uploaded Source

Built Distributions

pytokei-0.2.0-cp37-abi3-win_arm64.whl (1.1 MB view details)

Uploaded CPython 3.7+ Windows ARM64

pytokei-0.2.0-cp37-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.7+ Windows x86-64

pytokei-0.2.0-cp37-abi3-win32.whl (1.1 MB view details)

Uploaded CPython 3.7+ Windows x86

pytokei-0.2.0-cp37-abi3-musllinux_1_1_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.7+ musllinux: musl 1.1+ x86-64

pytokei-0.2.0-cp37-abi3-musllinux_1_1_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.7+ musllinux: musl 1.1+ ARM64

pytokei-0.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

pytokei-0.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

pytokei-0.2.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

pytokei-0.2.0-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl (2.5 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.12+ i686

pytokei-0.2.0-cp37-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

pytokei-0.2.0-cp37-abi3-macosx_10_7_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

File details

Details for the file pytokei-0.2.0.tar.gz.

File metadata

  • Download URL: pytokei-0.2.0.tar.gz
  • Upload date:
  • Size: 195.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pytokei-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f9f97bb77924a41ac7adb2e08462a372fb3da771c1e7c32545d800ccf4f628da
MD5 52569f8b3a57ce1826979e364dac74b9
BLAKE2b-256 c876d14328b86d6c6f9565ab4f2be6dffa84973486db69254cc8d23361d45e39

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-win_arm64.whl.

File metadata

  • Download URL: pytokei-0.2.0-cp37-abi3-win_arm64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.7+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 88a1874a567b9d4dec866aeda0352963d4436403a70fefeb4c683d122d09baed
MD5 8f555fdcf3dc742b53e79ad7a6635c1f
BLAKE2b-256 7ad69220ad8773c5c04543e99b1f010790c4a6fcc9e415a11ff3975643c8c011

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: pytokei-0.2.0-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3304567302fc7230f3358978315299e2d222b9dfb7cb4b5c023d0d87cb549e6a
MD5 a2351f61ad9b4557683545f77efbb13a
BLAKE2b-256 a768faa615a3674d39861495ad711934030f8a15a314a207cbdd1c982cf81474

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-win32.whl.

File metadata

  • Download URL: pytokei-0.2.0-cp37-abi3-win32.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.7+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 e7358af22962c8e957f2b4b4e0a0df565848e90fcce35bda1f7194b056b1df82
MD5 d63acefd41044e23ce04c7ce25886ba6
BLAKE2b-256 f8daacda24d949465a87a3832de557a3d6a7b692021d59415f5433e9190f7897

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2732f65a6fca1c5bc7703e30b6321ec6809dbb2b8673fd04fe3749dd8e4b1ed0
MD5 1b66926bd0a1035a6fd294d64dac5233
BLAKE2b-256 cc62bf04c693ba47fe3d698519d3338a150b211dd5580b2647766369021f72de

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 694fd2a7d7ece051a99888717b0323b97ca8e4a82229ba3e7f4f199faae45dee
MD5 9c31652a9e90a633440a8b593cdfbac2
BLAKE2b-256 e051cd2f57ae8372151be05a513f53c63ab6bbac778735ede9f08ea829214dfb

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e7719d5d28e3bb7e6bd50258fa037d186f6d59aeff99a2610af5d0d2c3b25600
MD5 23bb6dce57043b44349de294e6f97140
BLAKE2b-256 7240ee45fa922f9010e04375f6c4249ece428831837862833d3e077176adfc6a

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 33572cbcf2ccebcdb12c5796a45615d0b9a363d014721b541d41e55e30524115
MD5 471a107a1687d1a34ba60e826843e630
BLAKE2b-256 24826b3bd3cdc9066617fc78b26e28bb496b5cb5cc3127b6e652f955997df328

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e88e88a77e9da607b04ba7285c75cd350ac6668201e3bbae186b0953a708d140
MD5 48de68c83ddc934d5370f580f5071065
BLAKE2b-256 09bef1968ea57564412a536f03cfb42b8c68ac571ea63132cd4d1294ea454631

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 99d920102b0b4eafc680a516384d31a39035149e7e9031c91d53c73aa32c1eb8
MD5 4514bcd5aaace9e6ce9898cbd139aed4
BLAKE2b-256 b8525f919902f68bcd97746b7a81dc6b504596885bbb882ecfaa57d7001bab3f

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8fcbb57e829ec06b5906ccd91e847f7855abb2e28788bfdf4d38e232e1406116
MD5 1e3971691b6ab64cdc5ea117bb78f9aa
BLAKE2b-256 f895b1178bcc800f0e94ececaef12456bc2346a3e9cef8bdb9eae9c5440b34d2

See more details on using hashes here.

File details

Details for the file pytokei-0.2.0-cp37-abi3-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for pytokei-0.2.0-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 12ea7ef0f04b80fbd35fcc8a36e32f8623783fd3e36d1a894113007b57ed9bab
MD5 5974f1b8e6117cbc05f8e8ce19399d97
BLAKE2b-256 315f5224c017642c8c54f762c332d25f1b76c33a41599e12c4ea86df9f883986

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page