Method aliasing system with argument remapping and optional stub generation
Project description
Reflexsive
A lightweight Python library that enables concise method aliasing with optional argument remapping. Designed for ergonomic command interfaces, alternative method names, and API compatibility layers.
✨ Features
- Define aliases for class methods with different argument names.
- Supports instance, static, and class methods.
- Optional argument renaming per alias.
- Flexible usage with or without arguments.
- Stub file (
.pyi) generation for autocompletion support. - Optional prefixing for namespacing aliases.
- Strict conflict checking to prevent ambiguous mappings.
🔧 Installation
pip install reflexsive
🚀 Usage
from reflexsive import Reflexsive
class MyAPI(Reflexsive):
@Reflexsive.alias('short', username='u', password='p')
def authenticate(self, username, password):
return f"{username}:{password}"
obj = MyAPI()
print(obj.authenticate('admin', '123')) # 'admin:123'
print(obj.short('admin', '123')) # Same result using alias
print(obj.short(u='admin', p='123')) # Keyword aliasing
⚙️ Configuration Options
When using class A(Reflexsive, ...), you can pass configuration flags:
| Option | Type | Default | Description |
|---|---|---|---|
| allow_kwargs_override | bool | False | Allow alias names to override **kwargs |
| expose_alias_map | bool | False | (Planned) Expose alias map on class |
| docstring_alias_hints | bool | True | (Planned) Include alias info in docstrings |
| alias_prefix | str | None | Prefix added to all alias names |
Example 1: Without options
class Example(Reflexsive):
...
Example 2: With options
class Example(Reflexsive, create_pyi_stub=True, alias_prefix='a_'):
...
🧪 Testing
Tests are provided using pytest.\n
Tests cover:
- Alias mapping (positional and keyword)
- Class/Static method support
- Error handling for conflicting or invalid aliases
- Stub generation
- Prefix options
- Edge cases (built-in names, decorator order, etc.)
❗ Exception Types
The library defines the following custom exceptions:
AliasNameConflictError: Raised when an alias name conflicts with another method or alias.AliasArgumentError: Raised when alias mappings include invalid or forbidden parameters (e.g.,*args).AliasConfigurationError: Raised when invalid configuration options are passed to@aliased_class.
Notes
- Using classmethod/staticmethod decorators before
@aliasmakes Pylance complain - but does work at runtime
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reflexsive-0.1.0.tar.gz.
File metadata
- Download URL: reflexsive-0.1.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b11247d6461eeadfe60a53b7af8949d234560b6d695c8a16539cef430530e31
|
|
| MD5 |
ad32a6688923399fd6220a2e98085863
|
|
| BLAKE2b-256 |
c8306a77a7c5b999a88955121d716948764a7398761ce34b5e899e9ec6f6862e
|
File details
Details for the file reflexsive-0.1.0-py3-none-any.whl.
File metadata
- Download URL: reflexsive-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd45aab3c33fdf777e40a7d75c12bf1d14d75720ea0fca7898063bd20651b33c
|
|
| MD5 |
efdaa18d89f4a7525f45150db45873a1
|
|
| BLAKE2b-256 |
13bbb86741989880e521412df6cce2d3817a146c495aec9d3a76ac0127cf4564
|