Skip to main content

nCompass Tools Library

Project description

nc_utils

nCompass Library

A Python library providing immutable objects and traits for building robust applications.

Installation:

pip install ncompasslib

Basic Usage:

1. Creating an Immutable Object:

The Immutable class prevents attributes from being modified after they are first set.

from ncompasslib.immutable import Immutable

class MyClass(Immutable):
    def __init__(self):
        super().__init__()
        self.value = 42

obj = MyClass()
obj.value  # Returns 42
obj.value = 43  # Raises RuntimeError: Cannot change state once created

2. Using the Mutate Decorator:

When you need to modify an immutable object in a controlled way, use the mutate decorator.

from ncompasslib.immutable import Immutable, mutate

class Counter(Immutable):
    def __init__(self):
        super().__init__()
        self.count = 0
        
    @mutate
    def increment(self):
        self.count += 1

3. Creating Traits:

Traits are abstract base classes that are also immutable.

from ncompasslib.trait import Trait

class MyTrait(Trait):
    def __init__(self):
        super().__init__()
        self.trait_value = "example"

Features:

  • Immutable objects with controlled mutation
  • Trait system for creating abstract interfaces
  • Python 3.11+ support
  • Comprehensive test suite

For more information, visit: https://github.com/nCompass-tech/ncompasslib

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

ncompasslib-0.0.1.post5.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

ncompasslib-0.0.1.post5-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file ncompasslib-0.0.1.post5.tar.gz.

File metadata

  • Download URL: ncompasslib-0.0.1.post5.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for ncompasslib-0.0.1.post5.tar.gz
Algorithm Hash digest
SHA256 ac11e0f59c610de0351dc2694a42d7271296a15950cf350f9257e5a93085035c
MD5 118eda0a6e26c08e28ace882f128c231
BLAKE2b-256 f6e7f31643e2994f59ac0ea77259583ed5236fd8647c9cc984c77e3d60de1b53

See more details on using hashes here.

File details

Details for the file ncompasslib-0.0.1.post5-py3-none-any.whl.

File metadata

File hashes

Hashes for ncompasslib-0.0.1.post5-py3-none-any.whl
Algorithm Hash digest
SHA256 2ed72a8385ab6ba8615697996d60e676db6385210936e8e92c73bd6882e466bd
MD5 03dea1d4bdaa60bfbd5e2103c6e869f2
BLAKE2b-256 833e1d531dae1c606688b6f817de70393adfd8229d2e95ff22d59191e7ec617e

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