Skip to main content

track updates to python objects

Project description

✅ upd8

Version tracking for Python classes

🍐 wut?

Give your objects a version number that updates when you make changes.

⬇️ installation

pip install upd8
or
uv pip install upd8

▶️ Usage

Simple updates

>>> import upd8
>>> v = upd8.Versioned()
>>> v.version
0
>>> v.change()
1
>>> v.change()
2

Automatic versioning

Fields will update the version when you change them.

from upd8 import Versioned, field

class Doggo(Versioned):
    name = field("Pupper")
    legs = field(4)
>>> d = Doggo()
>>> d.legs -= 1
>>> d.name = "Tripod"
>>> d.version
2

Manual updates

change can be used as a context manager, and changes can be aborted by raising AbortChange:

>>> from upd8 import
>>> d = Doggo()
>>> d.legs = 1
>>> with d.change:
        if not d.legs:
            raise AbortChange()
        d.legs -= 1
>>> d.version
1

You can use async with Versioned.change from within asynchronous code.

Thread safety

If you're not using automatic updating fields, you can add thread safety to Versioned objects by decorating method with @waits, and avoid the context manager indenting your code with the @changes.

These work on async methods too.

class World(Versioned):
    _population: int = 8_000_000_000

    @changes
    def bottleneck(self, amount: float) -> int:
        survivors = int(self._population * amount)
        if survivors <= 0 or survivors == self._population:

            # set the return value in the AbortChange exception
            raise AbortChange(self._population)

        self._population = survivors
        return self._population

    @waits
    @property
    def population(self):
        return self._population

🔗 links

⚖️ License

Licensed under the WTFPL with one additional clause:

  1. Don't blame me.

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

upd8-0.0.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

upd8-0.0.2-py2.py3-none-any.whl (5.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file upd8-0.0.2.tar.gz.

File metadata

  • Download URL: upd8-0.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for upd8-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ceceb4e22fed4ff1d506b007e2fb8d12f09d178955dcd9033dc1d69b6696c1a2
MD5 dcc7dcdb8732810a052b88e381d46bf1
BLAKE2b-256 97b0cef5cd4a4bc9df62053770f8ebb783c854e5e39412dc07be2329551cc412

See more details on using hashes here.

File details

Details for the file upd8-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: upd8-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for upd8-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 85153ccafcbf3948b3000ee856b0b7766b0f40ea8ff8ca15b2621162732841a3
MD5 7b3d9afb5eab92c3861dab566c654e5c
BLAKE2b-256 f06b76ce057b45d48087f1c13881fcd6c4be446c4295c44bdb36e0b0e5991bc4

See more details on using hashes here.

Supported by

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