Skip to main content

A lightweight Python library for flexible data structures and reactive lists.

Project description

datatypeplus

Datatypeplus is a Python library that provides advanced data structures and reactive containers.


Import

from datatypeplus import FlexString, NList, EvolveList, EvolveElement, info


FlexString

A mutable, list-like string class with full edit and transformation support.

Example

fs = FlexString("Hello") fs.append(" World") fs[0] = "h" fs.replace("World", "Python") fs.upper() fs[0:3] = "Hey" fs.extend("!!") fs.insert(0, ">") print(fs) # >>> HEYLO PYTHON!!

Methods

append(value)
 Add text to the end of the string.

extend(value)
 Extend with multiple characters or another string.

insert(index, value)
 Insert text at a specific position.

replace(old, new)
 Replace all occurrences of a substring.

upper()
 Convert all characters to uppercase (in place).

lower()
 Convert all characters to lowercase (in place).

getitem(index) / setitem(index, value)
 Access or modify by index or slice.


NList

A labeled, multi-dimensional datatypeplus for structured data access.
Each axis has a name and markers, which can be used to locate data points.

Example

nl = NList( axes={ "Year": [2011, 2012, 2013], "Month": ["Jan", "Feb"], "City": ["NY", "LA"] }, default=0 )

nl.set(2011, "Jan", "NY", value=100) nl.set(2012, "Feb", "LA", value=200)

print(nl.get(2011, "Jan", "NY")) # 100 print(nl.get(2012, "Feb", "LA")) # 200 print(nl.get(2013, "Jan", "NY")) # 0 (default)

Methods

set(*markers, value)
 Set a value at the specified axis markers.

get(*markers)
 Retrieve a value using axis markers.

axes
 Dictionary of all defined axes.

shape
 List of axis lengths.

repr()
 Returns a string summary of the structure.


EvolveList and EvolveElement

Reactive lists that automatically trigger actions when certain conditions become true.

Example

el = EvolveList([10, 20, 30])

el[0].when(el[0] == 10).print("Element 0 hit 10!") el[2].when(el[2] == 15).do(lambda: print("Element 2 hit 15!"))

el[0].value = 10 el[2] = 15 el.append(40)

print(el)

Methods

append(value)
 Add an element to the list.

setitem(index, value)
 Set a value at a position; triggers conditions if met.

getitem(index)
 Return an EvolveElement wrapper for the element.

el[i].value
 Access or modify an element’s stored value.

el[i].when(condition)
 Define a reactive condition for an element.

el[i].when(...).do(action)
 Run a custom function when the condition becomes true.

el[i].when(...).print(message)
 Print a message when the condition becomes true.

check()
 Manually re-evaluate all conditions.


info()

Prints metadata about the library.

Example

print(info())

Output:

Datatypeplus v1.0
Includes: FlexString, NList, EvolveList, EvolveElement
License: MIT


File Structure

datatypeplus/

├── init.py
├── flow.py
├── setup.py
├── test.py
├── README.md
└── LICENSE.txt


Installation

Local install for development:

pip install -e .

After install:

from datatypeplus import *

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

datatypeplus-1.0.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datatypeplus-1.0.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file datatypeplus-1.0.0.tar.gz.

File metadata

  • Download URL: datatypeplus-1.0.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for datatypeplus-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9bb7d303e9ae9fd2140d9dc40de150f40f8769f3aa617c4925d8a8516140b824
MD5 069a5c18e2a1569a1d3001987266f122
BLAKE2b-256 2f30e9a202ccbc6f9bd553cc0812b49856852ba9392c998841cfe2d274b8ff47

See more details on using hashes here.

File details

Details for the file datatypeplus-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: datatypeplus-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for datatypeplus-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21239dd238eadbe76ad3dc7c03a1e90e72537d40ca07283259f4adf8dac0aed2
MD5 aa2467ce45288c0234ce828c6d1743bf
BLAKE2b-256 0f519435b423d27b3bc55143db1853c8bfe229ac2e6346beacfa42d3b2fe8f21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page