Python Subtypes

0.3.18 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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.

from subtypes import Str, List

# Enhanced string functionality
my_string = Str("Hello world")
formatted_string = my_string("from the other side")
print(f"Formatted string: {formatted_string}")
print(f"Title case: {my_string.title}")

# Enhanced list functionality
my_list = List([1, 2, 3])
my_list.append_unique(2)
my_list.append_unique(4)
print(f"Unique appends: {my_list}")

# Accessing underlying native type
print(f"Native list: {my_list.native}")

view raw JSON →