Skip to main content

Pact: Attribute Enforcement Metaclass for Python

Pact is a lightweight Python metaclass designed to enforce the presence and types of class attributes in subclasses
It helps you ensure that all subclasses implement the required attributes declared in the base class,
catching missing or mistyped attributes early with warnings and exceptions

Features

  • Enforce presence of specific class or instance attributes in subclasses
  • Type validation of annotated attributes
  • Raises PactException exception and emits warnings for missing or mismatched attributes

Installation

You can install this package via PIP: pip install python-pact

Usage

from pact import Pact


class Person(Pact):
    name: str
    age: int


class JohnDoe(Person):
    name = 'John Doe'
    age = 25


# This will raise PactException due to missing 'age':
class JaneDoe(Person):
    name = 'Jane Doe'

Metadata

Release files for python-pact 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-pact 0.1.1
File Size Uploaded
python_pact-0.1.1.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-pact 0.1.1
File Interpreter ABI Platform
python_pact-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.6 kB

Release files / python_pact-0.1.1.tar.gz

Download URL python_pact-0.1.1.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e9886bb41d86fcc2b6956ce733e8510f427b96775fd2f3b708261fc80b31ed41
BLAKE2b-256 checksum
How to use checksums
70f8bc048b66f2e208823670bf92745ff6691f45fb84153a8fb0e28c01dabe52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release files / python_pact-0.1.1-py3-none-any.whl

Download URL python_pact-0.1.1-py3-none-any.whl
Size 3.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c030870d12597836c133b74a845e76ed013c84f610df2e7cea36dea5b17cd45
BLAKE2b-256 checksum
How to use checksums
18dc4df95a354cda8cdf66100d4f791828f7d6f4d16681226f57952692e277be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page