Skip to main content

betterdata by gmanka

library for working with data. Features: automatic writing to disk when new data is added to an object, quick export to yml

navigation

installation^

pip install betterdata

usage^

from betterdata import Data

df = Data(
    data = {
        'key1': 'val1',
        'key2': 'val2',
    },
    file_path = 'data.yml'
)

after running this code it will automatically create file data.yml

key1: val1
key2: val2

if file already exists, then it will be overwritten

reading^

if you will not specify data argument, then data will be read from disk

from betterdata import Data

df = Data(
    file_path = 'data.yml'
)

print(df)
# {'key1': 'val1', 'key2': 'val2'}

if file does not exists then dict will be empty

from betterdata import Data
from pathlib import Path

Path('data.yml').unlink()

data = Data(
    file_path = 'data.yml'
)

print(data)
# {}

autosaves^

if you put something in the dictionary then it will also automatically written to disk

from betterdata import Data

data = Data(
    file_path = 'data.yml'
)

print(data)
# {}
print(Path('data.yml').exists())
# False

data['key1'] = 'val1'
data['key2'] = 'val2'

print(data)
# {'key1': 'val1', 'key2': 'val2'}
print(open('data.yml', 'r').read())
# key1: val1
# key2: val2

manual saves^

if you editing list in a dict then it will not automatically saved, but you can save it manually

from betterdata import Data
from pathlib import Path

Path('data.yml').unlink(missing_ok=True)
data = Data(
    file_path = 'data.yml'
)

print(data)
# {}
print(Path('data.yml').exists())
# False

data['list'] = [1, 2, 3]

print(data)
# {'list': [1, 2, 3]}
print(open('data.yml', 'r').read())
# list:
# - 1
# - 2
# - 3

data['list'].append('some very important data')

print(data)
# {'list': [1, 2, 3, 'some very important data']}
print(open('data.yml', 'r').read())
# list:
# - 1
# - 2
# - 3

# as you can see, appended data was not written on disk, so you can write it manually

data.to_file()

print(open('data.yml', 'r').read())
# list:
# - 1
# - 2
# - 3
# - some very important data

some syntax sugar^

from betterdata import Data

data = Data(
    {
        'key1': 'val1',
        'key2': 'val2',
    }
)

print(data)
# {'key1': 'val1', 'key2': 'val2'}

print(data['key1'])
# val1

print(data.key1)
# val1

print(data.to_str())
# key1: val1
# key2: val2

print('key2' in data)
# True

print('key3' in data)
# False

print(data['key3'])
# None

print(data.key3)
# AttributeError: 'Data' object has no attribute 'key3'

interactive input^

from betterdata import Data

data = Data()

data.interactive_input('key1')

it will interactively ask user to input value for key1

args:
item: str # key name
digits_to_int: bool = True # convert digits from str to int
kill_app_on_exit: bool = True # kill app if user select exit button
break_if_exist: bool = True # skip interactive input if key already in dict
sel: Sel = yes_no # you can specify Sel object from easyselect lib which will be used to confirm the value
text = None # change text which will be printed on the screen

license^

gnu gpl 3

Release files for betterdata 23.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for betterdata 23.0.2
File Size Uploaded
betterdata-23.0.2.tar.gz 180.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for betterdata 23.0.2
File Interpreter ABI Platform
betterdata-23.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 184.2 kB

Release files / betterdata-23.0.2.tar.gz

Download URL betterdata-23.0.2.tar.gz
Size 180.5 kB
Tags Source
SHA-256 checksum
How to use checksums
100a5110ac1d3bf0c149dfb71d8be31cf15c4b34e76513873968628d236b4846
BLAKE2b-256 checksum
How to use checksums
4dd4c03a8da70c6b17d88022c3790a73ada24b76ba09ffe4ad989a3d328a8a6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / betterdata-23.0.2-py3-none-any.whl

Download URL betterdata-23.0.2-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47df2da14bcd7e66200db788b23fe5f7ebfbd80b6259b73021cdf080b0c8b749
BLAKE2b-256 checksum
How to use checksums
628fd94f3c7cf7140df58f13b0fe29354ecf1b285d66344d619b47bb7656ecf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release history Release notifications | RSS feed

This release

23.0.2 This release

2 release files

23.0.1

2 release files

22.1.0

2 release files

22.0.9

2 release files

22.0.8

2 release files

22.0.7

2 release files

22.0.6

2 release files

22.0.4

2 release files

22.0.3

2 release files

22.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page