Metadata-Version: 2.1
Name: fast-protocol
Version: 1.0
Summary: A very simple Python model for declaring a protocol for checking if objects provide the desired functionality.
Home-page: https://github.com/ZechCodes/fast-protocol
License: MIT
Keywords: type,protocol,match,checking,interface
Author: Zech Zimmerman
Author-email: hi@zech.codes
Requires-Python: >=3.7,<4.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Project-URL: Documentation, https://github.com/ZechCodes/fast-protocol
Project-URL: Repository, https://github.com/ZechCodes/fast-protocol
Description-Content-Type: text/markdown

# fast-protocol
A very simple Python model for declaring a protocol for checking if objects provide the desired functionality.

## Installation
```shell
pip install fast-protocol
```

## Usage
To create a Fast Protocol just call the `fast_protocol.protocol` function passing it the names of the methods/attributes that the protocol should support.
```python
from fast_protocol import protocol

def example():
    ...

Callable = protocol("__call__")  # Create a protocol that matches objects with a dunder call method
match example:
    case Callable():
        print("example is callable")
```
This can be used outside a `match` statement using `isinstance`.
```python
if isinstance(example, Callable):
    print("example is callable")
```

Protocols are generated with the name `"FastProtocol"`. This name can be changed by creating a new instance of
`FastProtocolBuilder`. The name can be set traditionally by passing the name of the protocol to the `FastProtocolBuilder` class. Alternatively you can pass the protocol name as a subscript to an existing `FastProtocolBuilder` which will return a new instance that uses that name.

**Traditional approach:**
```python
from fast_protocol import FastProtocolBuilder

Callable = FastProtocolBuilder("Callable")("__call__")
```
**Alternative approach:**
```python
from fast_protocol import protocol

Callable = protocol["Callable"]("__call__")
```

