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)

Multi-condition using & (and), | (or), and ~ (not)

el[1].when((el[1] == 20) & (el[2] != 30)).do(lambda: el.setitem(1, 99)) el[2].when((el[2] > 10) | (el[0] == 10)).print("Element 2 triggered by OR condition") el[0].when(~(el[0] == 5)).print("Element 0 is NOT 5")

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.

|=or &=and ~=not

info()

Prints metadata about the library.

Example

print(info())

Output:

Datatypeplus v1.1.2
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 *

Upgrade

To upgrade:

pip install datatypeplus --upgrade

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.1.2.tar.gz (10.3 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.1.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for datatypeplus-1.1.2.tar.gz
Algorithm Hash digest
SHA256 d8b48b9bd61d8d1aea231fcefda00f7281b2da8f303a7aaeb3014dc21458711f
MD5 ac5b8115364b4b31c24ad93a45a55240
BLAKE2b-256 aa0a9b57f54319beb07e600b2a8fe4e8b63d4b6a68bc495761bf7bb2886070ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: datatypeplus-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.4 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bb125bedcb69d236018eb3051f8984995c8e11047707cde41b00119ffe9c57e3
MD5 a0a5d92013fce992c6a59cae20f5b115
BLAKE2b-256 a5a1c12abac6d306e89c1c54040bfbf86ad7064428213b658407e0f086f78cd7

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