Type Inference and Conversion Library for Python
Project description
splurge-typer
Type Inference and Conversion Library for Python
splurge-typer is a comprehensive Python library for inferring data types from string values and converting between different data representations. It can analyze individual string values or entire collections to determine the most appropriate Python data type.
Features
- Single Value Inference: Automatically detect the data type of individual string values
- Collection Analysis: Analyze sequences of values to determine dominant types
- Type Conversion: Convert strings to their inferred Python types
- Comprehensive Type Support: Handles integers, floats, booleans, dates, times, datetimes, and more
- Performance Optimized: Includes incremental processing for large datasets
- Flexible Parsing: Supports multiple date/time formats and handles edge cases
Installation
# Clone the repository
git clone https://github.com/jim-schilling/splurge-typer.git
cd splurge-typer
# Install in development mode
pip install -e .
Quick Start
Basic Usage
from splurge_typer import TypeInference, DataType
# Create a type inference instance
ti = TypeInference()
# Single value inference
print(ti.infer_type('123')) # DataType.INTEGER
print(ti.infer_type('1.23')) # DataType.FLOAT
print(ti.infer_type('true')) # DataType.BOOLEAN
print(ti.infer_type('2023-01-01')) # DataType.DATE
# Type conversion
print(ti.convert_value('123')) # 123 (int)
print(ti.convert_value('1.23')) # 1.23 (float)
print(ti.convert_value('true')) # True (bool)
Collection Analysis
# Analyze collections of values
values1 = ['1', '2', '3']
print(ti.profile_values(values1)) # DataType.INTEGER
values2 = ['1.1', '2.2', '3.3']
print(ti.profile_values(values2)) # DataType.FLOAT
values3 = ['1', '2.2', 'hello']
print(ti.profile_values(values3)) # DataType.MIXED
Supported Data Types
The library can infer the following data types:
INTEGER: Whole numbers ('123','-456','00123')FLOAT: Decimal numbers ('1.23','-4.56','1.0')BOOLEAN: True/false values ('true','false','True','False')DATE: Date values in various formats ('2023-01-01','01/01/2023','20230101')TIME: Time values ('14:30:00','2:30 PM','143000')DATETIME: Combined date and time ('2023-01-01T12:00:00','2023-01-01 12:00:00')STRING: Text data that doesn't match other patternsEMPTY: Empty strings or whitespace-only stringsNONE: Null values ('none','null',None)MIXED: Collections containing multiple data types
Advanced Usage
Handling Edge Cases
# Leading zeros are handled correctly
print(ti.infer_type('00123')) # DataType.INTEGER
# Invalid dates fall back to string
print(ti.infer_type('2023-13-01')) # May be interpreted as date in some formats
# Mixed collections
mixed_values = ['123', 'abc', '2023-01-01']
print(ti.profile_values(mixed_values)) # DataType.MIXED
Performance Considerations
For large datasets (>10,000 items), the library automatically enables incremental type checking for better performance:
large_dataset = [str(i) for i in range(50000)]
result = ti.profile_values(large_dataset) # Uses optimized incremental processing
API Reference
TypeInference Class
Methods
infer_type(value: str) -> DataType: Infer type of a single valueconvert_value(value: Any) -> Any: Convert value to its inferred typeprofile_values(values: Iterable[Any]) -> DataType: Analyze a collection of values
String Class
Low-level string processing utilities:
is_int_like(),is_float_like(),is_bool_like(), etc.to_int(),to_float(),to_bool(), etc.infer_type()- direct type inference
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Jim Schilling (c) 2025
Documentation
Further documentation and detailed usage guides are available in the docs/ folder:
- Detailed docs: docs/README-details.md
- API reference: docs/api/API-REFERENCE.md
Project details
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 splurge_typer-2025.1.0.tar.gz.
File metadata
- Download URL: splurge_typer-2025.1.0.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea4c8c4baf0a7abbee4274ef0e785b87089baa5b8dfc8c63caf2c08017d5928c
|
|
| MD5 |
63898d0739ae35758fb1d28ac747c1af
|
|
| BLAKE2b-256 |
4be9de57273ce7fd17e370e6f81d4f4583a7b73c979b3fc14812640591aa4216
|
File details
Details for the file splurge_typer-2025.1.0-py3-none-any.whl.
File metadata
- Download URL: splurge_typer-2025.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cade747f9e94a544a61cc86a96b2b68dc744049e5d224423d680e0bd4899478
|
|
| MD5 |
86b46a2d43332a9865e24152db33d05f
|
|
| BLAKE2b-256 |
b3dd13687dd65f260eee403be441198c4825d95fcb907ff7c1f3b84bbed9d18d
|