Skip to main content

Add your description here

Project description

ABCReg

ABCReg adds AnnotatedABC and AnnotatedABCMeta, which provide additional interface checking at registration time to ensure that registered virtual and ordinary subclasses are valid.

Use ABCReg if you are designing a plugin API or any other interface that might be implemented by an end user.

Defining the Interface

Use AnnotatedABC just like an ordinary ABC. Make sure to mark your API methods as abstract and provide type hints:

from abc import abstractmethod
from abcreg import AnnotatedABC

class Queryable(AnnotatedABC):
    @abstractmethod
    def query(self, **kwargs) -> str: ...

We recommend you use virtual inheritance:

@Queryable.register(VirtualQueryProvider)
class VirtualQueryProvider:
    def query(self, **kwargs) -> str:
        return "query result"

assert issubclass(VirtualQueryProvider, Queryable)
assert isinstance(VirtualQueryProvider(), Queryable)

But, regular inheritance will also work:

class QueryProvider(Queryable):
    def query(self, **kwargs) -> str:
        return "query result"

assert issubclass(QueryProvider, Queryable)

Requirements and Usage

Requries Python 3.10+. With UV, require with uv add abcreg.

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

abcreg-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

abcreg-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: abcreg-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for abcreg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b55821f0d97c50368c6dccbd367fe46f015c91c7213984e90f25b0bd55a846b8
MD5 38d5a4f6d54f88d80dc176005b726b09
BLAKE2b-256 4dca6b6bd4109c3784fe86612ebb64d234901125e95905f110a8614883a11a96

See more details on using hashes here.

File details

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

File metadata

  • Download URL: abcreg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for abcreg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 242885eccd982af8b19e6b2b7f135321c4d358cfdd54cb2dea2b337fc6296ef7
MD5 37c7701d5ce7bf216fb0dd3dd7cf0f16
BLAKE2b-256 8c1b09210e7185437c6e96f5413979f5655a87023162b66b12b9b6d382e9f173

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