Extended Language Support for Python
Project description
LangEx
Extended Language Support for Python
Installation
pip install langex
About
LangEx is an experimental Python library that introduces additional language-level constructs using decorators, metadata inspection, and runtime validation.
It focuses on enabling capabilities that Python does not strictly enforce by default, such as interface-like structures, structured metadata, and runtime type validation.
The project builds small language utilities that operate on Python objects (functions, classes, and other callables) to inspect, validate, and extend their behavior while remaining fully compatible with standard Python.
Features
- Interface-like constructs for Python classes
- Metadata extraction for Python objects and callables
- Runtime validation utilities
- Decorator-based language extensions
- Runtime argument and return type checking
- Lightweight core inspection tools
Example
Defining and using an Interface
from langex.core.classes import implements, interface
from langex.core.functions import args_required, returns
@interface
class InterfaceClass:
@args_required(int)
@returns(int)
def method1(self, a: int) -> int:
...
@args_required(str)
@returns(str)
def method2(self, b: str) -> str:
...
@implements(InterfaceClass)
class ImplementationClass:
def __init__(self, factor):
self.factor = factor
def method1(self, a: int) -> int:
return a * self.factor
def method2(self, b: str) -> str:
return b.upper() * self.factor
instance = ImplementationClass(3)
print(instance.method1(5)) # prints 15 in console
print(instance.method2("hi")) # prints "HIHIHI" in console
print(instance.method1("5")) # raises Langex Validation Error
print(instance.method2(5)) # raises Langex Validation Error
Runtime Type Enforcement
from langex.core.functions import args_required, returns
@args_required(int, int)
@returns(int)
def add(a, b):
return a + b
print(add(1, 2)) # prints the integer 3 in console
print(add("1", "2")) # raises Langex Validation Error
LangEx records type metadata and enforces it when the function is executed.
Project Structure
langex
├── __init__.py
├── __main__.py
├── classes
│ ├── __init__.py
│ ├── class_meta.py
│ └── methods_meta.py
├── core
│ ├── __init__.py
│ ├── classes.py
│ └── functions.py
├── errors
│ ├── __init__.py
│ ├── instantiation.py
│ ├── langex.py
│ ├── misapplication.py
│ ├── unimplemented.py
│ └── validation.py
├── functions
│ ├── __init__.py
│ ├── args_meta.py
│ ├── function_meta.py
│ ├── returns_meta.py
│ └── signature.py
├── utils
│ ├── __init__.py
│ ├── extracter.py
│ └── matcher.py
└── validation
├── __init__.py
├── kw_args_validator.py
├── pos_args_validator.py
├── returns_validator.py
└── validator.py
Module Overview
- The core module contains the core decorators and utilities for language extensions.
- The classes module contains tools for class inspection and interface-like constructs.
- The functions module contains tools for function metadata and signature inspection.
- The validation modules contain logic for validating function arguments and return values at runtime.
- The utils module contains helper functions for type matching and other utilities.
- The errors module defines custom exceptions for validation and other errors.
Design Philosophy
LangEx is designed around a few principles:
- Pure Python implementation
- Explicit developer intent
- Small composable language utilities
Rather than acting as a framework, LangEx provides foundational language tools that can be used to build higher-level abstractions.
Status
Experimental and under active development.
APIs and structure may evolve as the project grows.
Links
Made with <3 by AttAditya
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 langex-0.2.6.tar.gz.
File metadata
- Download URL: langex-0.2.6.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77fee819ecab5717066b36aa20401c7b249a8545a7e03ff32d07cce52e440fb3
|
|
| MD5 |
a3094637649667f30581757c71559303
|
|
| BLAKE2b-256 |
cb6e21939e9cf29b302f4a81f0a653d5dd369b5374d7c4ea150c1546775b0146
|
File details
Details for the file langex-0.2.6-py3-none-any.whl.
File metadata
- Download URL: langex-0.2.6-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fcfe895e2f6dc2c2279a1c8cdf8491f8f30f5a2e88c01ecbd6a22a3cf2fefaa
|
|
| MD5 |
b87009df159ad2f626ef7f7c97ccac29
|
|
| BLAKE2b-256 |
e1ea583419929f79cfc93d44066ae27510835a0a9fbb6d32062e9513c1a76b99
|