pysubtypes is a Python library that provides subclasses for common Python built-in types (like Str, Int, List, Dict) with additional functionality and convenience methods. It aims to enhance native types with common utility methods and properties. The library maintains a frequent release cadence, primarily with patch versions, and is currently at version 0.3.18.
pip install pysubtypesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates importing and using the `Str` and `List` subtypes. It showcases method chaining, enhanced string formatting, and unique list appends. The `.native` property allows access to the underlying built-in Python type.
Profile critical sections of code if performance is a concern, and test against expected behaviors. Use the `.native` property to revert to the built-in type if specific native behavior is required.
Consult the source code on GitHub for specific type behaviors if ambiguity arises. Leverage the `.native` property when interacting with external libraries or functions that expect standard Python types to avoid unexpected method calls.
For operations where raw performance is paramount, consider using the native Python built-in types or converting `pysubtypes` instances to their native counterparts using the `.native` property before entering performance-sensitive loops.