Skip to main content

Augment your Python objects with drop-in behaviours and signals

Project description

bricklib

Augment your Python objects with drop-in behaviours and (soon) signals.

Overview

bricklib is a library designed to enhance your Python objects with modular behaviors and (soon) signals. It allows you to effortlessly attach and manage relationships between objects through well-defined protocols and mixins.

Features

Version 0.1.0

This initial release provides the following protocols and mixins:

  • AttachmentSocket Protocol
  • Attachment Protocol
  • AttachmentSocketMixin
  • AttachmentMixin

Functionality

Protocols

  • AttachmentSocket:

    • Represents objects capable of attaching other objects.
    • Requires an attach(attachment: Attachment) method.
    • Contains a list of attachments.
  • Attachment:

    • Represents objects that can be attached to other objects.
    • Requires a _attach_to(socket: AttachmentSocket) method.
    • Contains a reference to the parent socket.

Mixins

  • AttachmentSocketMixin:

    • Provides the attach method.
    • Implements the AttachmentSocket protocol.
  • AttachmentMixin:

    • Provides the _attach_to method.
    • Implements the Attachment protocol.

Example Usage

Here's a basic example demonstrating how to use Bricklib:

from bricklib.mixins import AttachmentSocketMixin, AttachmentMixin
from bricklib.types import AttachmentSocket, Attachment

class MySocket(AttachmentSocketMixin):
    """
    Custom socket class inheriting from AttachmentSocketMixin.
    """
    pass

class MyAttachment(AttachmentMixin):
    """
    Custom attachment class inheriting from AttachmentMixin.
    """
    pass

# Create a socket instance
socket = MySocket()

# Ensure the socket instance implements the AttachmentSocket protocol
assert isinstance(socket, AttachmentSocket)
assert socket.attachments == []  # No attachments initially

# Create an attachment instance
attachment = MyAttachment()

# Ensure the attachment instance implements the Attachment protocol
assert isinstance(attachment, Attachment)
assert attachment.parent is None

# Attach the attachment to the socket
socket.attach(attachment)

# Verify that the attachment was successfully added
assert attachment in socket.attachments
assert socket is attachment.parent

Future Plans

  • Allow classes to restrict the subtypes of sockets and attachments they'll accept.
  • Enhance typing support to ensure compatibility with both runtime checks and static checkers.

Installation

To install Bricklib, use pip:

pip install bricklib

Testing (dev)

To test, use pytest:

pytest -svv

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

bricklib-0.1.1.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

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

bricklib-0.1.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file bricklib-0.1.1.tar.gz.

File metadata

  • Download URL: bricklib-0.1.1.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for bricklib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cbdc83b79e7c4a9dadf467985a8506832be086b5ce95df9998605653d00f5983
MD5 86501ec1324bcd18c3111a2ba4bb3207
BLAKE2b-256 96df17a26c3ef8a9f4276301f0fee2946d80fdd432708e5c4765ff64bb7b7c72

See more details on using hashes here.

File details

Details for the file bricklib-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: bricklib-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for bricklib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64e6f1649a403a1f5bf45853c6e64a6454ffc8625783ad5e1b2eb9733a597a00
MD5 cd41df1b692132a299575bee07bc6699
BLAKE2b-256 b2dc08da67cb7b35bcc19a7f6061360e03d9ad196a8c2532267824983a38678a

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