Registry / serialization / pysubtypes

pysubtypes

JSON →
library0.3.18pypypi✓ verified 24d ago

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 pysubtypes
INSTALL
IMPORT
SIG · PYSUBTYPES
P
pysubtypes
serializationpythonv0.3.18
Install
13.1s avg
Import
Disk
211MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.18 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 209.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 13.1s · import 0.000s · 203MB
211MB installed
● package 211MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Str
from subtypes import Str
from pysubtypes import Str

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}")
Debug
Known issues
gotchaWhen subclassing built-in types, be aware that not all native C-level optimizations and behaviors of the original types may be fully preserved. While `pysubtypes` aims for compatibility, some subtle differences in performance or memory usage might occur.
fix
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.
affects: All versions
gotchaThe library heavily relies on implicit `__call__` and other magic methods for its convenience features. This can sometimes lead to unexpected behavior if you're not familiar with how these methods are overloaded, especially when chaining operations or passing `pysubtypes` instances to functions expecting strict built-in types.
fix
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.
affects: All versions
gotchaDirect instantiation of built-in types might be preferred in performance-critical loops due to the overhead introduced by subclassing and additional method lookups. The utility of `pysubtypes` shines in code readability and expressiveness over raw speed for basic operations.
fix
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.
affects: All versions
Upgrade
Version history
0.3.18latest on PyPI · released Feb 1, 2021
Audit
Dependencies
pythonrequiredRequired for execution.
Agent activity
26 hits · last 30 days
node
24
Resources
pysubtypes — pip install pysubtypes · libregistry