NTProp
A simple mechanism for using Network Tables entries as semi-transparent member variables
Installation
Using your Python package manager of choice, just install the ntprop package from PyPI.
pip install ntprop
Usage
To start using these, you just need to import NTPropertyHost from ntprop and have
your class inherit from it. From there, any member varaible that is of the types NumberProperty,
BooleanProperty, or StringProperty (also from ntprop) will act like a simple, strictly-typed
member variable that transparently updates and is updated by the relevant NT entry.
Example
from ntprop import NTPropertyHost, NumberProperty
class Foo(NTPropertyHost):
# for purposes of type-checking here, we could just call this a float, since there's no difference in
# usage at runtime. This is only valid if the owning class is an NTPropertyHost.
bar: NumberProperty
def __init__(self):
self.bar = NumberProperty("ntbar", default=1, readonly=False) #defaults are 0.0 and False, respectively
def do_something(self):
# += may work?
self.bar = self.bar + 1
print(self.bar)
It's also possible to use an NTProperty without it being a member of ah NTPropertyHost. To do that, you just
need to use the get and set methods of the type. NOTE: These methods are not available in NTPropertyHosts
since that type already does the necessary calls to get and set behind the scenes and resolves them prior to
returning a value.
Bindings
It's possible to bind to changes to a property using the NTProperty.bind method, and providing a callback
compatible with Callable[[Any], None]. The callback will be called any time the value changes, both from the
local program and NetworkTables.
To bind a callback for a property in an NTPropertyHost, call the NTPropertyHost.bind method, passing the
name of the NT entry with the callback using kwargs syntax. If your entry name is incompatible with Python
name syntax, you can use a dict with the entry name as the key and the callback as the associated value.
Either argument method allows multiple key-value pairs, so you can bind multiple callbacks at once.
Note: Be aware that local changes may cause the callback to be called multiple times. It is recommended to only use idempotent (same every time) callbacks as well as not make them any more expensive to call than strictly necessary.
Warning: There is no guarantee of the callback being called in the same thread it was created it (e.g. the NT
listener that does background updates runs in a different non-Python thread), so any interactions with the outside
world must be thread safe. If you don't know what that means, you're probably fine, and if you do know what it means,
but not how to fix it, visit the Python docs on the threading module.
Metadata
Release files for ntprop 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ntprop-0.3.0.tar.gz | 3.8 kB | Without provenance | Details for ntprop-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ntprop-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for ntprop-0.3.0-py3-none-any.whl |
Total release size: 8.3 kB
Release files / ntprop-0.3.0.tar.gz
| Download URL | ntprop-0.3.0.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c72756f0bef181bcde98bdcc9d1a41c9cad6c4a49b2d900f050ea7ccd4db94c2
|
|
BLAKE2b-256 checksum How to use checksums |
55b5d86ec3e57acd49affd1fb4dd82740651f3465d407ea533449674be85f7fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.14.4 Darwin/23.4.0
|
Release files / ntprop-0.3.0-py3-none-any.whl
| Download URL | ntprop-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ebb5ab6c00871afdbf02b3640a19d30bd07b83ca9151559a0747b2adf591088
|
|
BLAKE2b-256 checksum How to use checksums |
db608bd508321abc65a62fc7d86a3e30c5ebb3ffb7477003cda9a0c5df05feff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.14.4 Darwin/23.4.0
|
Security for ntprop 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.