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.post2.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.post2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncompasslib-0.0.1.post2.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.post2.tar.gz
Algorithm Hash digest
SHA256 6e70c7f8e0d15a136ffaf87a81e8164567f89c717fb9942e50f7c8cd9289b6bf
MD5 36a3e72862ba11173bdd89ca0ac625f8
BLAKE2b-256 67a084b62b4417ee88613ed7f64bcb46a8be02d54d09cacffc9353f6e9511ad4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ncompasslib-0.0.1.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 178a3d51e387b2d1a94a0348d8d1da8e532aa687456569b60a7c4455767a3cf6
MD5 537543304b2c0198c3d3e6e0353bb5b6
BLAKE2b-256 ab6a5608fc409a971f2fadf20cb2ae23870b54834c132c8ea5676affef6fd36e

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