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.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 *

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.0.tar.gz (9.6 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.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: datatypeplus-1.1.0.tar.gz
  • Upload date:
  • Size: 9.6 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.0.tar.gz
Algorithm Hash digest
SHA256 b17274040cd2be562620bb9a65735f34e391b75dec184f5d22f2d7ed090fbc28
MD5 212a16fbb1fac84fb24688905dcc6aed
BLAKE2b-256 2ce75191ce53b80056a01d4acafabf2224c672ceea342ef1c776da3123a46db2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: datatypeplus-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87334987b766d21b8579e22f411a57273b341f7264f8a1c5d904a3f56efe1677
MD5 6bb56c921ea322379b0d71c70c4d3b99
BLAKE2b-256 0fb10655840336fc4aad174f44faed106525c257d4209e60a4bdc266f8a87ab5

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