Skip to content

JonesBeach/python-interfaces

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-interfaces

This project is a learning exercise in Python metaprogramming. I wondered what Java-style interfaces would look like in Python.

For a tad more context, you can read this blog post.

Installation

pip install python-interfaces

Usage

from interface import interface

class Iterable:
    def be_iterable(self):
        pass

@interface(Iterable)
class Foo:
    def __init__(self):
        pass

# raises InterfaceException

Local Development

git clone https://github.com/tyleragreen/python-interfaces.git && cd python-interfaces
virtualenv ~/.env/interface
source ~/.env/interface/bin/activate

pip install -r requirements.txt

# Since the tests live outside the package, we install the package in editable mode
pip install -e .

# Run the formatter
black .

# Run the linter
ruff check .

# Check the static types
pyright

# Run the unit tests
pytest

Other Ideas

  1. Support dunder methods
  2. Enforce method signatures
  3. Require interface methods to be empty/abstract/pass-only

About

Bringing interfaces to Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors 3

  •  
  •  
  •  

Languages