python-ntp


Namepython-ntp JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/jsiembida/python-ntp
SummaryNone
upload_time2024-07-16 09:09:43
maintainerNone
docs_urlNone
authorJarek Siembida
requires_python>=3.5
licenseASF2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            

### python-ntp

Pure python, clean room implementation of NTP client based directly on
[RFC5905](https://datatracker.ietf.org/doc/html/rfc5905).

* No extra dependencies, it is a single source file that works
  in vanilla Python 3.5 or newer.
* Tested to work on Linux, macOS and Windows.
* Any number of NTP servers can be used.
* NTP servers v4 and v3 are supported.
* And so are IPv4 and IPv6.
* The full suite of client side algorithms is implemented.
  From periodic polling of each peer, to finding consensus,
  to aggregate offset and jitter. Except the logic of correcting
  the local time, as this was never the goal. It still can
  be used to correct local system time, see the examples below.
* CLI offers functionality similar to [ntpdate(8)](https://linux.die.net/man/8/ntpdate),
  again, except the logic of setting the local time which can be worked around.


### API

Intended use is a thread running in a loop:

```
from time import sleep
from ntp import NtpArena

# IPv4 of IPv6 addresses must be fed into NtpArena, hostnames must be resolved first.
ntp = NtpArena(addresses=["217.114.59.66", "82.69.171.134"])

while True:
    pause = ntp.query_peers()
    leap, offset, jitter = ntp.calculate_state()
    print(offset)
    sleep(pause)
```

Lower level API is exposed via `NtpMessage` and `NtpAssociation` classes.


### CLI

Keep running and showing NTP time every minute:

```
ntp.py --output-interval 60 pool.ntp.org time.nist.gov time.google.com
```

One shot run, returning offset between local and NTP time:

```
ntp.py --output-count 1 --output-format '{offset:+}' pool.ntp.org
```

Feeding the output to [date(1)](https://linux.die.net/man/1/date), in order to set
the system time. This is crude PLL logic, as in the clock discipline algorithm.

```
date --set="$(ntp.py --output-interval 30 --output-count 1 pool.ntp.org)"
```

Use `ntp.py --help` to learn more about available options.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jsiembida/python-ntp",
    "name": "python-ntp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jarek Siembida",
    "author_email": "jarek.siembida@gmail.com",
    "download_url": null,
    "platform": null,
    "description": "\n\n### python-ntp\n\nPure python, clean room implementation of NTP client based directly on\n[RFC5905](https://datatracker.ietf.org/doc/html/rfc5905).\n\n* No extra dependencies, it is a single source file that works\n  in vanilla Python 3.5 or newer.\n* Tested to work on Linux, macOS and Windows.\n* Any number of NTP servers can be used.\n* NTP servers v4 and v3 are supported.\n* And so are IPv4 and IPv6.\n* The full suite of client side algorithms is implemented.\n  From periodic polling of each peer, to finding consensus,\n  to aggregate offset and jitter. Except the logic of correcting\n  the local time, as this was never the goal. It still can\n  be used to correct local system time, see the examples below.\n* CLI offers functionality similar to [ntpdate(8)](https://linux.die.net/man/8/ntpdate),\n  again, except the logic of setting the local time which can be worked around.\n\n\n### API\n\nIntended use is a thread running in a loop:\n\n```\nfrom time import sleep\nfrom ntp import NtpArena\n\n# IPv4 of IPv6 addresses must be fed into NtpArena, hostnames must be resolved first.\nntp = NtpArena(addresses=[\"217.114.59.66\", \"82.69.171.134\"])\n\nwhile True:\n    pause = ntp.query_peers()\n    leap, offset, jitter = ntp.calculate_state()\n    print(offset)\n    sleep(pause)\n```\n\nLower level API is exposed via `NtpMessage` and `NtpAssociation` classes.\n\n\n### CLI\n\nKeep running and showing NTP time every minute:\n\n```\nntp.py --output-interval 60 pool.ntp.org time.nist.gov time.google.com\n```\n\nOne shot run, returning offset between local and NTP time:\n\n```\nntp.py --output-count 1 --output-format '{offset:+}' pool.ntp.org\n```\n\nFeeding the output to [date(1)](https://linux.die.net/man/1/date), in order to set\nthe system time. This is crude PLL logic, as in the clock discipline algorithm.\n\n```\ndate --set=\"$(ntp.py --output-interval 30 --output-count 1 pool.ntp.org)\"\n```\n\nUse `ntp.py --help` to learn more about available options.\n\n\n",
    "bugtrack_url": null,
    "license": "ASF2.0",
    "summary": null,
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/jsiembida/python-ntp"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "078a207e29565f905558aa897e5283040fb01a57978c531198f9da7d9a0b736b",
                "md5": "967e1c446d00edb8ddcb3ef9d28cb81d",
                "sha256": "b2510c5f784e80ed8c725c73b015504ccc7c3e2b009d5d80932b475493f5eccd"
            },
            "downloads": -1,
            "filename": "python_ntp-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "967e1c446d00edb8ddcb3ef9d28cb81d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 14173,
            "upload_time": "2024-07-16T09:09:43",
            "upload_time_iso_8601": "2024-07-16T09:09:43.719269Z",
            "url": "https://files.pythonhosted.org/packages/07/8a/207e29565f905558aa897e5283040fb01a57978c531198f9da7d9a0b736b/python_ntp-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-16 09:09:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jsiembida",
    "github_project": "python-ntp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "python-ntp"
}
        
Elapsed time: 0.25288s