Skip to main content

Comprehensive Object-Based Runtime Architecture

Project description

COBRA 🐍

Comprehensive Object-Based Runtime Architecture

COBRA is an experimental Python library that introduces optional runtime-enforced object-oriented programming concepts while remaining fully compatible with standard Python.

Python follows the philosophy of "We're all consenting adults here." COBRA embraces that philosophy while providing developers with the option to enforce stronger object-oriented constraints when building large or enterprise-grade applications.


Why COBRA?

Python intentionally relies on conventions instead of strict access modifiers.

For example:

class BankAccount:
    def __reset_pin(self):
        ...

Although name mangling discourages accidental access, private members are still accessible when explicitly referenced.

COBRA explores an alternative approach by introducing optional runtime validation for concepts such as:

  • Private methods
  • Protected methods
  • Private fields
  • Final methods
  • Runtime contracts
  • Interface validation

The goal is not to replace Python, but to provide an optional layer of additional runtime guarantees.


Features

Current (v0.1)

  • @private
  • ✅ Runtime access validation
  • ✅ Custom exception hierarchy
  • ✅ Unit tests
  • ✅ Extensible architecture

Planned

  • @protected
  • PrivateField
  • ProtectedField
  • @final
  • @override
  • Runtime contracts
  • Interface support
  • Performance optimisations

Installation

pip install cobra-oop

For development:

pip install -e .

Quick Example

from cobra import CobraObject, private


class BankAccount(CobraObject):

    @private
    def reset_pin(self):
        print("PIN reset")

    def change_pin(self):
        self.reset_pin()


account = BankAccount()

account.change_pin()      # ✅ Allowed
account.reset_pin()       # ❌ Raises PrivateAccessError

Project Structure

cobra/
├── decorators.py
├── fields.py
├── base.py
├── exceptions.py
├── utils.py
└── __init__.py

Roadmap

The development roadmap can be found in:

docs/roadmap.md

Architecture decisions are documented under:

docs/adr/

Philosophy

COBRA is designed around a few simple principles:

  • Keep Pythonic syntax.
  • Make strictness optional.
  • Prefer explicit behaviour over hidden magic.
  • Build small, testable components.
  • Learn by exploring Python internals.

Contributing

Contributions, suggestions, and discussions are always welcome.

If you discover an issue or have an idea for improving COBRA, feel free to open an issue or submit a pull request.


License

This project is licensed under the MIT License.


"Python trusts developers. COBRA helps developers trust each other." 🐍

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

cobra_oop-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

cobra_oop-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file cobra_oop-0.1.0.tar.gz.

File metadata

  • Download URL: cobra_oop-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for cobra_oop-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d9c09457701ca6b92ccc1e440933512b3a0044a96ea89e5af3c31e7452f3ddf1
MD5 1d6324d9ff1966535b616d7248dd5c2a
BLAKE2b-256 cbc505802693cf58287caaaa35e939ed8b32756cd7f7ce9166c0be558135e7f7

See more details on using hashes here.

File details

Details for the file cobra_oop-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cobra_oop-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for cobra_oop-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60ae82e82b201ceaf7a80a5f34dd79ed09cdc1b6b33d93531282c352737d2394
MD5 7549dc24ff9c91909651b96724ebaa0a
BLAKE2b-256 b6a1ad75c6e7295178c8feb72e63dd8a87f462a029123ee00c40d3eea1400cda

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