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

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncompasslib-0.0.1.post4.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.post4.tar.gz
Algorithm Hash digest
SHA256 1eed14b19f3cbdd092953ffabd14cfbc4040723530d1a8ffaee5b996775e7f79
MD5 72c73e8ec9a98f43f4919257a81cfb60
BLAKE2b-256 346c546976466f9bfe4a3db30519334080d63a34d16d7aa68e5ebff729f0ce9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ncompasslib-0.0.1.post4-py3-none-any.whl
Algorithm Hash digest
SHA256 98116c745a54ee8b48857b5b50957eb59f0f19dcd4ec3d6c5a06c98a15df2254
MD5 946693937f826ee852a0378123d9c86a
BLAKE2b-256 8720b950f79cae72545a8ed3979ede413a3980340a916cf49fdb0c39c3bb35d8

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