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

Uploaded Python 3

File details

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

File metadata

  • Download URL: datatypeplus-1.1.1.tar.gz
  • Upload date:
  • Size: 10.2 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.1.tar.gz
Algorithm Hash digest
SHA256 5b81c2078236122beb71750f67066e7dcaa9b80ae35be744c1ba570aebdb47f4
MD5 bc2c57d7fe2aed8e7b8139c2eb8fe682
BLAKE2b-256 5cde9fc6c4bc6e7b69ec1ef7e9a63940205a567f3bf442f1ac02c931f30fd337

See more details on using hashes here.

File details

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

File metadata

  • Download URL: datatypeplus-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6fcd47f64798e208b17e3ec3a1c98064d468a3ba3974bb898fddf795e558fe94
MD5 4ffcd06660dc62c21a8d3736e819c7db
BLAKE2b-256 6e371f2183e76ce09511947a324f8f10c247d1eb610138053aa2cb094290dbcc

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