Metadata-Version: 2.1
Name: pyzf
Version: 1.0.2
Summary: pyzf is Zeff Muks's enhancement for working with Python
Author: Zeff Muks
Author-email: zeffmuks@gmail.com
License: MIT
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiofiles ==0.8.0
Requires-Dist: aiohappyeyeballs ==2.3.7
Requires-Dist: aiohttp ==3.10.4
Requires-Dist: aiosignal ==1.3.1
Requires-Dist: aiosqlite ==0.17.0
Requires-Dist: annotated-types ==0.7.0
Requires-Dist: asyncpraw ==7.7.1
Requires-Dist: asyncprawcore ==2.4.0
Requires-Dist: attrs ==24.2.0
Requires-Dist: bitarray ==2.9.2
Requires-Dist: bitstring ==4.2.3
Requires-Dist: certifi ==2024.7.4
Requires-Dist: cffi ==1.17.0
Requires-Dist: charset-normalizer ==3.3.2
Requires-Dist: click ==8.1.7
Requires-Dist: contourpy ==1.2.1
Requires-Dist: cycler ==0.12.1
Requires-Dist: filelock ==3.15.4
Requires-Dist: fonttools ==4.53.1
Requires-Dist: frozenlist ==1.4.1
Requires-Dist: fsspec ==2024.6.1
Requires-Dist: huggingface-hub ==0.24.5
Requires-Dist: idna ==3.7
Requires-Dist: Jinja2 ==3.1.4
Requires-Dist: kiwisolver ==1.4.5
Requires-Dist: loguru ==0.7.2
Requires-Dist: MarkupSafe ==2.1.5
Requires-Dist: matplotlib ==3.9.2
Requires-Dist: mpmath ==1.3.0
Requires-Dist: multidict ==6.0.5
Requires-Dist: networkx ==3.3
Requires-Dist: numpy ==1.26.4
Requires-Dist: opencv-python ==4.10.0.84
Requires-Dist: osxmetadata ==1.3.5
Requires-Dist: packaging ==24.1
Requires-Dist: pandas ==2.2.2
Requires-Dist: pillow ==10.4.0
Requires-Dist: prawcore ==2.4.0
Requires-Dist: psutil ==6.0.0
Requires-Dist: py-applescript ==1.0.3
Requires-Dist: py-cpuinfo ==9.0.0
Requires-Dist: pycparser ==2.22
Requires-Dist: pydantic ==2.8.2
Requires-Dist: pydantic-settings ==2.4.0
Requires-Dist: pydantic-core ==2.20.1
Requires-Dist: pyobjc-core ==10.3.1
Requires-Dist: pyobjc-framework-AppleScriptKit ==10.3.1
Requires-Dist: pyobjc-framework-AppleScriptObjC ==10.3.1
Requires-Dist: pyobjc-framework-AVFoundation ==10.3.1
Requires-Dist: pyobjc-framework-Cocoa ==10.3.1
Requires-Dist: pyobjc-framework-CoreAudio ==10.3.1
Requires-Dist: pyobjc-framework-CoreMedia ==10.3.1
Requires-Dist: pyobjc-framework-CoreServices ==10.3.1
Requires-Dist: pyobjc-framework-FSEvents ==10.3.1
Requires-Dist: pyobjc-framework-Quartz ==10.3.1
Requires-Dist: pyobjc-framework-ScriptingBridge ==10.3.1
Requires-Dist: pyparsing ==3.1.2
Requires-Dist: python-dateutil ==2.9.0.post0
Requires-Dist: python-dotenv ==1.0.1
Requires-Dist: pytz ==2024.1
Requires-Dist: PyYAML ==6.0.2
Requires-Dist: regex ==2024.7.24
Requires-Dist: requests ==2.32.3
Requires-Dist: safetensors ==0.4.4
Requires-Dist: scipy ==1.14.0
Requires-Dist: seaborn ==0.13.2
Requires-Dist: six ==1.16.0
Requires-Dist: sympy ==1.13.2
Requires-Dist: tokenizers ==0.19.1
Requires-Dist: torch ==2.4.0
Requires-Dist: torchvision ==0.19.0
Requires-Dist: tqdm ==4.66.5
Requires-Dist: transformers ==4.44.0
Requires-Dist: typing-extensions ==4.12.2
Requires-Dist: tzdata ==2024.1
Requires-Dist: ultralytics ==8.2.78
Requires-Dist: ultralytics-thop ==2.0.2
Requires-Dist: update-checker ==0.18.0
Requires-Dist: urllib3 ==2.2.2
Requires-Dist: websocket-client ==1.8.0
Requires-Dist: xattr ==1.1.0
Requires-Dist: yarl ==1.9.4

# PyZF

[![PyPI version](https://badge.fury.io/py/pyzf.svg)](https://badge.fury.io/py/pyzf)

![PyZF](https://zf-static.s3.us-west-1.amazonaws.com/pyzf-logo128.png)</p>

PyZF is Zeff Muks's enhancements for working with Python.

```
pip install pyzf
```

## Interfaces

Those coming from other languages like `Go` or `TypeScript` will be familiar with the concept of interfaces. It enables you to define a contract without worrying about concrete classes. While Python has Abstract Base Classes, there are some limitations:

1. You cannot define optional methods in ABCs
2. It's not easy to compose multiple ABCs
3. Hard to ensure a class implements an ABC

PyZF provides a robust and flexible way to define and implement _interfaces_ in Python. It offers features like interface declarations, default methods, optional methods, and interface composition.

### Features

PyZF Interfaces provides a powerful way to define contracts between different parts of your code, improving maintainability and reducing errors.

#### 1. Interface Definition

Define interfaces using the `Interface` class:

```python
from pyzf.interfaces import Interface, method, default_method, optional_method

class Jedi(Interface):
    @method
    def speak(self) -> str:
        pass

    @method
    def force_power(self) -> int:
        pass

    @default_method
    def default_greet(self) -> str:
        return f"May the Force be with you. I am {self.speak()}"
```

#### 2. Method Types

In `Go`, all methods are required but in `pyzf`, you can define also define optional methods.

- `@method`: Regular methods that must be implemented
- `@default_method`: Methods with default implementations
- `@optional_method`: Methods that can be optionally implemented

#### 3. Interface Composition

Combine multiple interfaces to create more complex ones:

```python
class Sith(Interface):
    @method
    def force_lightning(self) -> None:
        pass

    @optional_method
    def optional_force_choke(self) -> None:
        pass

class ForceUser(Jedi, Sith):
    pass
```

#### 4. Implementation and Validation

Use the `@implements` decorator to ensure a class correctly implements an interface:

```python
@implements(ForceUser)
class DarthVader:
    def speak(self) -> str:
        return "I am Darth Vader, Dark Lord of the Sith"

    def force_power(self) -> int:
        return 950

    def force_lightning(self) -> None:
        print("⚡️ Force Lightning!")
```

In the above example:

* We do not need to implement the `default_greet` method, as it will be inherited.
* We do not need to implement the `optional_force_choke` method, as it is optional.

If you try to instantiate a class that does not implement an interface, you will get an `InterfaceError`.

```python
from pyzf.interfaces import InterfaceError

@implements(ForceUser)
class DarthVader:
    pass

vader = DarthVader() # InterfaceError
```

In `Go`, this is equivalent an interface assertion:

```go
var _ ForceUser = (*DarthVader)(nil) # Compiler error if DarthVader does not implement ForceUser
```

In `TypeScript`, this is equivalent to an interface assertion:

```typescript
const vader = new DarthVader(); // Compiler error if DarthVader does not implement ForceUser
```

#### 5. Usage

Use interfaces for type hinting and polymorphism:

```python
def use_the_force(obj: ForceUser):
    print(f"Type of obj: {type(obj)}")
    print(obj.default_greet())

vader = DarthVader()
use_the_force(vader)
```

In `Go`, this is equivalent to:

```go
type ForceUser interface {
    // ...
}

func use_the_force(obj ForceUser)  {  // ForceUser is an interface type
    // ...
}
```

## License

[MIT](LICENSE)
