tickpy


Nametickpy JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/blex-max/tickpy
SummaryTimer classes with a focus on periodic timing in while loops
upload_time2025-02-18 23:17:33
maintainerNone
docs_urlNone
authorAlex Byrne
requires_python>=3.13
licenseGPL-3.0-or-later
keywords timing embedded fsm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # TickPy

Convenient timing classes with a focus on periodic timing in while loops.

The bulk of this module is given to `Ticker` classes - counters which increment tracking a given period. Much like a counter you might find on low-resource chip, when working on embedded applications. By example, if you set up a ticker with a period of 10ms, and in each iteration of your main loop you call `.update()` on the ticker, each time 10ms has elapsed the ticker will increment it's counter by 1. This is combined with various conveniences, such as functions for checking 'how long since' or 'has this period elapsed' and so on.

There are two flavours of `Ticker`, each with a slightly different sense of time. `FreeTicker` will increment it's counter by as many periods have passed since last updated - most accurately approximating an independent timer on a chip. `IncTicker` will only ever increment it's counter by 1 for each call to `.update()` - this is convenient if you don't want to bother worrying about what happens if the timer skips. Each flavour also has an extended child class, `Ext...Ticker` - this class adds some slightly more complicated state tracking of periods checked, to avoid reporting that a period has elapsed more than once for a given loop.

Also provided are some very simple `Timer` classes, which just track time without any period internal sense of period. These are `StaticTimer`, where `now` is fixed to the last time the timer was updated, and `Timer`, where `now` is always right now. These come with a couple of convience functions each, though these are less extensive than those present for the Tickers.

All classes rely on `time.perf_counter()` for reasonably accurate timing. This is the reason for the reliance on `python 3.13`, since the underlying implementation of `perf_counter()` has changed since `3.12`

I developed this module to use when working with finite state machines, or in other words programs where the main function is a long-running while loop. My applications are usually pretty simple; most often I'm prototyping what may become a C program on a chip - this module lets me approximate that scenario pretty quickly. It's all pretty simple stuff in here and it's a very small library - have a quick read of the code in the `tickpy/` dir.

## Dependencies

- `python >= 3.13`

## Installation

The latest version is available via PyPi for standard installation, e.g.
```
pip install tickpy
```
or however is most appropriate for your needs.

From source or a github release:
```
poetry install
```
or
```
pip install .
```

## Testing

A test suite with approximately complete coverage is available for this repo. It is implemented with pytest.

## Plausible extensions

Things I can/will implement at request or my need:
  - ensure compatibility with some older versions of python3
  - extensions to period checking functions for both timer and ticker classes
    - extend ticker `.cmod()` to optionally take a `period_start` parameter - effectively decoupling period tracking from the start time when desired, and returning False if `.counter` has not yet reached period start.
  - optionally autoupdate when calling cmod and so on. Almost certainly ill-advised for the applications I envisage using this module for however.

## Licence

GPL3 applies to all files and folders in this repo.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/blex-max/tickpy",
    "name": "tickpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.13",
    "maintainer_email": null,
    "keywords": "timing, embedded, fsm",
    "author": "Alex Byrne",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/db/7c/5bdef529d8d921cc157a382da2168b7de2614b5d6376d324dc5b45cfece3/tickpy-0.6.0.tar.gz",
    "platform": null,
    "description": "# TickPy\n\nConvenient timing classes with a focus on periodic timing in while loops.\n\nThe bulk of this module is given to `Ticker` classes - counters which increment tracking a given period. Much like a counter you might find on low-resource chip, when working on embedded applications. By example, if you set up a ticker with a period of 10ms, and in each iteration of your main loop you call `.update()` on the ticker, each time 10ms has elapsed the ticker will increment it's counter by 1. This is combined with various conveniences, such as functions for checking 'how long since' or 'has this period elapsed' and so on.\n\nThere are two flavours of `Ticker`, each with a slightly different sense of time. `FreeTicker` will increment it's counter by as many periods have passed since last updated - most accurately approximating an independent timer on a chip. `IncTicker` will only ever increment it's counter by 1 for each call to `.update()` - this is convenient if you don't want to bother worrying about what happens if the timer skips. Each flavour also has an extended child class, `Ext...Ticker` - this class adds some slightly more complicated state tracking of periods checked, to avoid reporting that a period has elapsed more than once for a given loop.\n\nAlso provided are some very simple `Timer` classes, which just track time without any period internal sense of period. These are `StaticTimer`, where `now` is fixed to the last time the timer was updated, and `Timer`, where `now` is always right now. These come with a couple of convience functions each, though these are less extensive than those present for the Tickers.\n\nAll classes rely on `time.perf_counter()` for reasonably accurate timing. This is the reason for the reliance on `python 3.13`, since the underlying implementation of `perf_counter()` has changed since `3.12`\n\nI developed this module to use when working with finite state machines, or in other words programs where the main function is a long-running while loop. My applications are usually pretty simple; most often I'm prototyping what may become a C program on a chip - this module lets me approximate that scenario pretty quickly. It's all pretty simple stuff in here and it's a very small library - have a quick read of the code in the `tickpy/` dir.\n\n## Dependencies\n\n- `python >= 3.13`\n\n## Installation\n\nThe latest version is available via PyPi for standard installation, e.g.\n```\npip install tickpy\n```\nor however is most appropriate for your needs.\n\nFrom source or a github release:\n```\npoetry install\n```\nor\n```\npip install .\n```\n\n## Testing\n\nA test suite with approximately complete coverage is available for this repo. It is implemented with pytest.\n\n## Plausible extensions\n\nThings I can/will implement at request or my need:\n  - ensure compatibility with some older versions of python3\n  - extensions to period checking functions for both timer and ticker classes\n    - extend ticker `.cmod()` to optionally take a `period_start` parameter - effectively decoupling period tracking from the start time when desired, and returning False if `.counter` has not yet reached period start.\n  - optionally autoupdate when calling cmod and so on. Almost certainly ill-advised for the applications I envisage using this module for however.\n\n## Licence\n\nGPL3 applies to all files and folders in this repo.\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "Timer classes with a focus on periodic timing in while loops",
    "version": "0.6.0",
    "project_urls": {
        "Homepage": "https://github.com/blex-max/tickpy"
    },
    "split_keywords": [
        "timing",
        " embedded",
        " fsm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8bc1b55b0d5b1343f799f591cf32feae2cf138290043bd54ef12c481eabae9d4",
                "md5": "dc2cd63d38802831a366ef26992837b8",
                "sha256": "788913a5c8fca0cea0db0759ba59cc7fe007fdfa50afba480e5113843734b37c"
            },
            "downloads": -1,
            "filename": "tickpy-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dc2cd63d38802831a366ef26992837b8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.13",
            "size": 17317,
            "upload_time": "2025-02-18T23:17:32",
            "upload_time_iso_8601": "2025-02-18T23:17:32.656499Z",
            "url": "https://files.pythonhosted.org/packages/8b/c1/b55b0d5b1343f799f591cf32feae2cf138290043bd54ef12c481eabae9d4/tickpy-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db7c5bdef529d8d921cc157a382da2168b7de2614b5d6376d324dc5b45cfece3",
                "md5": "a55903236c731a994c62e05e2282131e",
                "sha256": "66239f68cd274cd12eb95871519ecd62c18411b18376cbe5d7b11aeee41ce01e"
            },
            "downloads": -1,
            "filename": "tickpy-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a55903236c731a994c62e05e2282131e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.13",
            "size": 15820,
            "upload_time": "2025-02-18T23:17:33",
            "upload_time_iso_8601": "2025-02-18T23:17:33.847517Z",
            "url": "https://files.pythonhosted.org/packages/db/7c/5bdef529d8d921cc157a382da2168b7de2614b5d6376d324dc5b45cfece3/tickpy-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-18 23:17:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "blex-max",
    "github_project": "tickpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "tickpy"
}
        
Elapsed time: 0.71445s