跳转到主要内容

内存高效的Python对象

项目描述

https://github.com/nucleic/atom/workflows/Continuous%20Integration/badge.svg https://github.com/nucleic/atom/workflows/Documentation%20building/badge.svg https://codecov.io/gh/nucleic/atom/branch/main/graph/badge.svg Documentation Status Ruff

Atom是一个用于创建具有动态初始化、验证和对象属性变更通知等增强功能的内存高效Python对象的框架。它为Enaml UI框架提供默认的模型绑定行为。

示例

from atom.api import Atom, Str, Range, Bool, observe


class Person(Atom):
    """ A simple class representing a person object.

    """
    last_name = Str()

    first_name = Str()

    age = Range(low=0)

    debug = Bool(False)

    @observe('age')
    def debug_print(self, change):
        """ Prints out a debug message whenever the person's age changes.

        """
        if self.debug:
            templ = "{first} {last} is {age} years old."
            s = templ.format(
                first=self.first_name, last=self.last_name, age=self.age,
            )
            print(s)

    def _default_first_name(self):
        return 'John'


john = Person(last_name='Doe', age=42)
john.debug = True
john.age = 43  # prints message
john.age = 'forty three'   # raises TypeError

从atom 0.8.0版本开始,atom对象也可以使用类型注解定义。

from atom.api import Atom, observe

class InventoryItem(Atom):
    """Class for keeping track of an item in inventory."""

    name: str
    unit_price: float
    quantity_on_hand: int = 0

    def total_cost(self) -> float:
        return self.unit_price * self.quantity_on_hand

    @observe("unit_price")
    def check_for_price_reduction(self, change):
        savings = change.get("oldvalue", 0) - change.get("value")
        if savings > 0:
            print(f"Save ${savings} now on {self.name}s!")

>>> w = InventoryItem(name="widget", unit_price=1.99, quantity_on_hand=10)
>>> w.unit_price = 1.00
Save $0.99 now on widgets!

有关版本信息,请参阅修订历史

项目详情


下载文件

下载您平台对应的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分布

atom-0.10.5.tar.gz (170.2 kB 查看哈希值)

上传时间 源代码

构建分布

atom-0.10.5-cp312-cp312-win_amd64.whl (133.2 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

atom-0.10.5-cp312-cp312-win32.whl (120.6 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86

atom-0.10.5-cp312-cp312-musllinux_1_2_x86_64.whl (2.4 MB 查看哈希值)

上传时间 CPython 3.12 musllinux: musl 1.2+ x86-64

atom-0.10.5-cp312-cp312-musllinux_1_2_i686.whl (2.4 MB 查看哈希值)

上传时间 CPython 3.12 musllinux: musl 1.2+ i686

atom-0.10.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

atom-0.10.5-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

atom-0.10.5-cp312-cp312-macosx_11_0_arm64.whl (148.7 kB 查看哈希值)

上传于 CPython 3.12 macOS 11.0+ ARM64

atom-0.10.5-cp312-cp312-macosx_10_9_x86_64.whl (151.2 kB 查看哈希值)

上传于 CPython 3.12 macOS 10.9+ x86-64

atom-0.10.5-cp312-cp312-macosx_10_9_universal2.whl (245.1 kB 查看哈希值)

上传于 CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

atom-0.10.5-cp311-cp311-win_amd64.whl (132.4 kB 查看哈希值)

上传于 CPython 3.11 Windows x86-64

atom-0.10.5-cp311-cp311-win32.whl (119.7 kB 查看哈希值)

上传于 CPython 3.11 Windows x86

atom-0.10.5-cp311-cp311-musllinux_1_2_x86_64.whl (2.3 MB 查看哈希值)

上传于 CPython 3.11 musllinux: musl 1.2+ x86-64

atom-0.10.5-cp311-cp311-musllinux_1_2_i686.whl (2.4 MB 查看哈希值)

上传于 CPython 3.11 musllinux: musl 1.2+ i686

atom-0.10.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ x86-64

atom-0.10.5-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

atom-0.10.5-cp311-cp311-macosx_11_0_arm64.whl (147.2 kB 查看哈希值)

上传于 CPython 3.11 macOS 11.0+ ARM64

atom-0.10.5-cp311-cp311-macosx_10_9_x86_64.whl (148.5 kB 查看哈希值)

上传于 CPython 3.11 macOS 10.9+ x86-64

atom-0.10.5-cp311-cp311-macosx_10_9_universal2.whl (241.1 kB 查看哈希值)

上传于 CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

atom-0.10.5-cp310-cp310-win_amd64.whl (132.5 kB 查看哈希值)

上传于 CPython 3.10 Windows x86-64

atom-0.10.5-cp310-cp310-win32.whl (119.8 kB 查看哈希值)

上传于 CPython 3.10 Windows x86

atom-0.10.5-cp310-cp310-musllinux_1_2_x86_64.whl (2.3 MB 查看哈希值)

上传于 CPython 3.10 musllinux: musl 1.2+ x86-64

atom-0.10.5-cp310-cp310-musllinux_1_2_i686.whl (2.3 MB 查看哈希值)

上传于 CPython 3.10 musllinux: musl 1.2+ i686

atom-0.10.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ x86-64

atom-0.10.5-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

atom-0.10.5-cp310-cp310-macosx_11_0_arm64.whl (147.3 kB 查看哈希值)

上传于 CPython 3.10 macOS 11.0+ ARM64

atom-0.10.5-cp310-cp310-macosx_10_9_x86_64.whl (148.5 kB 查看哈希值)

上传于 CPython 3.10 macOS 10.9+ x86-64

atom-0.10.5-cp310-cp310-macosx_10_9_universal2.whl (241.1 kB 查看哈希值)

上传于 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

atom-0.10.5-cp39-cp39-win_amd64.whl (132.7 kB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

atom-0.10.5-cp39-cp39-win32.whl (120.0 kB 查看哈希值)

上传时间 CPython 3.9 Windows x86

atom-0.10.5-cp39-cp39-musllinux_1_2_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.9 musllinux: musl 1.2+ x86-64

atom-0.10.5-cp39-cp39-musllinux_1_2_i686.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.9 musllinux: musl 1.2+ i686

atom-0.10.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.17+ x86-64

atom-0.10.5-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

atom-0.10.5-cp39-cp39-macosx_11_0_arm64.whl (147.3 kB 查看哈希值)

上传时间 CPython 3.9 macOS 11.0+ ARM64

atom-0.10.5-cp39-cp39-macosx_10_9_x86_64.whl (148.5 kB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ x86-64

atom-0.10.5-cp39-cp39-macosx_10_9_universal2.whl (241.1 kB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

atom-0.10.5-cp38-cp38-win_amd64.whl (132.4 kB 查看哈希值)

上传时间 CPython 3.8 Windows x86-64

atom-0.10.5-cp38-cp38-win32.whl (119.9 kB 查看哈希值)

上传时间 CPython 3.8 Windows x86

atom-0.10.5-cp38-cp38-musllinux_1_2_x86_64.whl (2.3 MB 查看哈希值)

上传于 CPython 3.8 musllinux: musl 1.2+ x86-64

atom-0.10.5-cp38-cp38-musllinux_1_2_i686.whl (2.3 MB 查看哈希值)

上传于 CPython 3.8 musllinux: musl 1.2+ i686

atom-0.10.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ x86-64

atom-0.10.5-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

atom-0.10.5-cp38-cp38-macosx_11_0_arm64.whl (146.9 kB 查看哈希值)

上传于 CPython 3.8 macOS 11.0+ ARM64

atom-0.10.5-cp38-cp38-macosx_10_9_x86_64.whl (148.2 kB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ x86-64

atom-0.10.5-cp38-cp38-macosx_10_9_universal2.whl (240.6 kB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

由以下支持