heliclockter


Nameheliclockter JSON
Version 1.3.0 PyPI version JSON
download
home_page
SummaryA robust way of dealing with datetimes in python by ensuring all datetimes are timezone aware at runtime.
upload_time2024-02-05 12:26:17
maintainer
docs_urlNone
author
requires_python>=3.9
licenseBSD 3-Clause License Copyright (c) 2022, Channable All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords datetime heliclockter timezone timezones tz tzinfo
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Heliclockter
=======

`heliclockter` is a robust way of dealing with datetimes and timestamps in python. It is statically
type checkable as well as runtime enforceable and integrates with [pydantic][pydantic].

The library exposes 3 classes:

- `datetime_tz`, a datetime ensured to be timezone-aware.
- `datetime_local`, a datetime ensured to be timezone-aware in the local timezone.
- `datetime_utc`, a datetime ensured to be timezone-aware in the UTC+0 timezone.

as well as various utilities to instantiate, mutate and serialize those classes.

See our [announcement post][announcement] for a more background on why we wrote `heliclockter`.

[pydantic]: https://github.com/pydantic/pydantic
[announcement]: https://www.channable.com/tech/heliclockter-timezone-aware-datetimes-in-python

Examples
-------

Say you want to create a timestamp of the current time in the UTC+0 timezone.

```python
from heliclockter import datetime_utc

now = datetime_utc.now()
# datetime_utc(2022, 11, 4, 15, 28, 10, 478176, tzinfo=zoneinfo.ZoneInfo(key='UTC'))
```

Or imagine you want to create a timestamp 2 hours in the future from now:

```python
from heliclockter import datetime_utc

two_hours_from_now = datetime_utc.future(hours=2)
# datetime_utc(2022, 11, 4, 17, 28, 52, 478176, tzinfo=zoneinfo.ZoneInfo(key='UTC'))
```

Features
--------

* Runtime enforcable timezone-aware datetimes
* Utilities for instantiating, mutating and serializing timezone-aware datetimes
* Statically type check-ble
* Pydantic integration
* Extensive test suite
* No third party dependencies

Installation
------------

To install `heliclockter`, simply: 

    $ pip install heliclockter

More examples
-------------

Imagine you want to parse a JSON response from a third party API which includes a timestamp, and you
want to handle the timestamp in the UTC+0 timezone regardless of how the 3rd party relays it. This 
can easily be done with `pydantic` and `heliclockter`:

```python
import requests
from pydantic import BaseModel
from heliclockter import datetime_utc


class ApiResponse(BaseModel):
    current_time: datetime_utc


def get_response() -> ApiResponse:
    response = requests.get('https://some-api.com/time')
    return ApiResponse.parse_obj(response.json())
```

The returned `ApiResponse` instance is guaranteed to have parsed the `current_time` attribute 
as UTC+0 no matter how the api provided the timestamp. If no timezone information is provided, 
it will be assumed to be UTC+0.

Expanding the module can be done with little effort, by creating a new class that inherits `datetime_tz`:

```python
from zoneinfo import ZoneInfo
from heliclockter import datetime_tz


class datetime_cet(datetime_tz):
    """
    A `datetime_cet` is a `datetime_tz` but which is guaranteed to be in the 'CET' timezone.
    """

    assumed_timezone_for_timezone_naive_input = ZoneInfo('CET')
```

If you have a timestamp which is naive, *but* the timezone in which it is made is known to you,
you can easily create a `datetime_tz` instance using your own defined classes:

```python
aware_dt = datetime_cet.strptime('2022-11-04T15:49:29', '%Y-%m-%dT%H:%M:%S')
# datetime_cet(2022, 11, 4, 15, 49, 29, tzinfo=zoneinfo.ZoneInfo(key='CET'))
```

About the name
--------------

`heliclockter` is a word play of "clock" and "helicopter". The module aims to guide the user and help them make little to no mistakes when handling datetimes, just like a [helicopter parent](https://en.wikipedia.org/wiki/Helicopter_parent) strictly supervises their children.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "heliclockter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "datetime,heliclockter,timezone,timezones,tz,tzinfo",
    "author": "",
    "author_email": "Peter Nilsson <peter.nilsson@channable.com>",
    "download_url": "https://files.pythonhosted.org/packages/d6/8a/fece817a7243be70ffed78ed1a41437c4e0366c088da2e9c50d3e9cb911d/heliclockter-1.3.0.tar.gz",
    "platform": null,
    "description": "Heliclockter\n=======\n\n`heliclockter` is a robust way of dealing with datetimes and timestamps in python. It is statically\ntype checkable as well as runtime enforceable and integrates with [pydantic][pydantic].\n\nThe library exposes 3 classes:\n\n- `datetime_tz`, a datetime ensured to be timezone-aware.\n- `datetime_local`, a datetime ensured to be timezone-aware in the local timezone.\n- `datetime_utc`, a datetime ensured to be timezone-aware in the UTC+0 timezone.\n\nas well as various utilities to instantiate, mutate and serialize those classes.\n\nSee our [announcement post][announcement] for a more background on why we wrote `heliclockter`.\n\n[pydantic]: https://github.com/pydantic/pydantic\n[announcement]: https://www.channable.com/tech/heliclockter-timezone-aware-datetimes-in-python\n\nExamples\n-------\n\nSay you want to create a timestamp of the current time in the UTC+0 timezone.\n\n```python\nfrom heliclockter import datetime_utc\n\nnow = datetime_utc.now()\n# datetime_utc(2022, 11, 4, 15, 28, 10, 478176, tzinfo=zoneinfo.ZoneInfo(key='UTC'))\n```\n\nOr imagine you want to create a timestamp 2 hours in the future from now:\n\n```python\nfrom heliclockter import datetime_utc\n\ntwo_hours_from_now = datetime_utc.future(hours=2)\n# datetime_utc(2022, 11, 4, 17, 28, 52, 478176, tzinfo=zoneinfo.ZoneInfo(key='UTC'))\n```\n\nFeatures\n--------\n\n* Runtime enforcable timezone-aware datetimes\n* Utilities for instantiating, mutating and serializing timezone-aware datetimes\n* Statically type check-ble\n* Pydantic integration\n* Extensive test suite\n* No third party dependencies\n\nInstallation\n------------\n\nTo install `heliclockter`, simply: \n\n    $ pip install heliclockter\n\nMore examples\n-------------\n\nImagine you want to parse a JSON response from a third party API which includes a timestamp, and you\nwant to handle the timestamp in the UTC+0 timezone regardless of how the 3rd party relays it. This \ncan easily be done with `pydantic` and `heliclockter`:\n\n```python\nimport requests\nfrom pydantic import BaseModel\nfrom heliclockter import datetime_utc\n\n\nclass ApiResponse(BaseModel):\n    current_time: datetime_utc\n\n\ndef get_response() -> ApiResponse:\n    response = requests.get('https://some-api.com/time')\n    return ApiResponse.parse_obj(response.json())\n```\n\nThe returned `ApiResponse` instance is guaranteed to have parsed the `current_time` attribute \nas UTC+0 no matter how the api provided the timestamp. If no timezone information is provided, \nit will be assumed to be UTC+0.\n\nExpanding the module can be done with little effort, by creating a new class that inherits `datetime_tz`:\n\n```python\nfrom zoneinfo import ZoneInfo\nfrom heliclockter import datetime_tz\n\n\nclass datetime_cet(datetime_tz):\n    \"\"\"\n    A `datetime_cet` is a `datetime_tz` but which is guaranteed to be in the 'CET' timezone.\n    \"\"\"\n\n    assumed_timezone_for_timezone_naive_input = ZoneInfo('CET')\n```\n\nIf you have a timestamp which is naive, *but* the timezone in which it is made is known to you,\nyou can easily create a `datetime_tz` instance using your own defined classes:\n\n```python\naware_dt = datetime_cet.strptime('2022-11-04T15:49:29', '%Y-%m-%dT%H:%M:%S')\n# datetime_cet(2022, 11, 4, 15, 49, 29, tzinfo=zoneinfo.ZoneInfo(key='CET'))\n```\n\nAbout the name\n--------------\n\n`heliclockter` is a word play of \"clock\" and \"helicopter\". The module aims to guide the user and help them make little to no mistakes when handling datetimes, just like a [helicopter parent](https://en.wikipedia.org/wiki/Helicopter_parent) strictly supervises their children.\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License  Copyright (c) 2022, Channable All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "A robust way of dealing with datetimes in python by ensuring all datetimes are timezone aware at runtime.",
    "version": "1.3.0",
    "project_urls": {
        "Homepage": "https://github.com/channable/heliclockter"
    },
    "split_keywords": [
        "datetime",
        "heliclockter",
        "timezone",
        "timezones",
        "tz",
        "tzinfo"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4ff61060d7f351ade4c94a0d6eff012fbcf06974bb5c22deab5da33a22ca6925",
                "md5": "2c5a00a6cbed6b497fa3e5b8530a9521",
                "sha256": "f4086fd75ddf7dd55ea1a9e5562ff940b88bc9dac30b9ccc3ea1c577aaead35e"
            },
            "downloads": -1,
            "filename": "heliclockter-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2c5a00a6cbed6b497fa3e5b8530a9521",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7381,
            "upload_time": "2024-02-05T12:26:13",
            "upload_time_iso_8601": "2024-02-05T12:26:13.911028Z",
            "url": "https://files.pythonhosted.org/packages/4f/f6/1060d7f351ade4c94a0d6eff012fbcf06974bb5c22deab5da33a22ca6925/heliclockter-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d68afece817a7243be70ffed78ed1a41437c4e0366c088da2e9c50d3e9cb911d",
                "md5": "5bec6ee644490d88681aea6ed4345d96",
                "sha256": "3c30d6d1d42d5af1809f95a95fea1b25d210bc556f27c69a43e46aac989bd360"
            },
            "downloads": -1,
            "filename": "heliclockter-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5bec6ee644490d88681aea6ed4345d96",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 15594,
            "upload_time": "2024-02-05T12:26:17",
            "upload_time_iso_8601": "2024-02-05T12:26:17.354643Z",
            "url": "https://files.pythonhosted.org/packages/d6/8a/fece817a7243be70ffed78ed1a41437c4e0366c088da2e9c50d3e9cb911d/heliclockter-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-05 12:26:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "channable",
    "github_project": "heliclockter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "heliclockter"
}
        
Elapsed time: 0.19640s