ezpyzy
Utility functions solving common but annoying problems.
Installation
pip install ezpyzy
Usage
import ezpyzy as ez
Easily save and load .txt, .json, .csv, and .pkl
text_file = ez.File('foo.txt')
json_file = ez.File('bar.json')
csv_file = ez.File('baz.csv')
pkl_file = ez.File('qux.pkl')
text_file.save('Hello, world!')
json_file.save({'a': 1, 'b': 2})
csv_file.save([[1, 2], [3, 4]])
pkl_file.save({1, 2, 3, 4})
assert text_file.load() == 'Hello, world!'
assert json_file.load() == {'a': 1, 'b': 2}
assert csv_file.load() == [[1, 2], [3, 4]]
assert pkl_file.load() == {1, 2, 3, 4}
Easily cache function results in a file
@ez.autocache
def heavy_workload():
...
return {'a': 1, 'b': 2}
x = heavy_workload(save='foo.json') # Save result after calculating
x = heavy_workload(load='foo.json') # Load result without calculating
Capture all args passed to a function in a dict
@ez.allargs
def foo(a, b, c, allargs=None):
print(allargs)
return a + b + c
foo(1, 2, 3) # Prints {'a': 1, 'b': 2, 'c': 3}
Automatically fill parameters by default with object attributes
@dc.dataclass
class Foo:
a: int
b: int
c: int
@ez.update_settings
def bar(self, a=None, b=None, c=None):
return a + b + c
foo = Foo(0, 1, 2)
print(foo.bar(5)) # Prints 8
Replace dataclass attributes by mutation with type hinting
@dc.dataclass
class Foo:
a: int
b: int
c: int
foo = Foo(0, 1, 2)
ez.replace(foo, b=3, c=5)
print(foo) # Prints Foo(a=0, b=3, c=5)
with ez.replace(foo, a=2):
print(foo) # Prints Foo(a=2, b=3, c=5)
print(foo) # Prints Foo(a=0, b=3, c=5)
Bind arguments (functools.partial) with type hinting
def foo(a: int, b: int, c: int):
return a + b + c
bar = ez.bind(foo)(a=1, b=2)
print(bar(c=3)) # Prints 6
Easy notification emails
ez.email(
'recipient@gmail.com',
'Subject Line',
"""Body of email.""",
)
To use, create a file ~/.pw/gmail.json (easiest to use an app password using gmail).
{
"smtp_server": "smtp.gmail.com",
"smtp_port": 587,
"sender_email": "address@gmail.com",
"sender_password": "app_password"
}
Automatically generate human-readable names for objects
print(ez.denominate()) # Prints a cool name like "DaringBespin"
Automatically generate a short-ish UUID (12 chars)
print(ez.uuid()) # Prints something like "A5_H2ka4f33S"
Shushes stdout and stderr
with ez.shush():
print('This will not print.')
Quick hacky way to run sequential tests
with check("My first test"):
x = [1, 2, 3]
assert x[0] == 1
with check("My second test"):
x[1] = 4
assert sum(x) == 8
Print-style debugging that keeps variables from the previous run
Kind of like if jupyter notebook had a baby with using a bunch of print statements to debug code.
data = load_data_for_a_long_time()
ez.explore() # Prints nearby variables and pauses execution
process_data() # will not run yet
After moving the explore() call and hitting enter...
data = load_data_for_a_long_time() # will not run again
process_data() # will run now
ez.explore() # Prints nearby variables and pauses execution
Dataframes but with type hinting
@dc.dataclass
class Foo(ez.Table):
id: ez.ColID = None
name: ez.ColStr = None
age: ez.ColInt = None
table = Foo.of([
['1', 'Alice', 20],
['2', 'Bob', 21],
['3', 'Charlie', 22],
])
for row in table:
print(row().name) # Type hinted. Prints Alice, Bob, Charlie
print(table)
Foo Table: 3 cols x 3 rows
id|name |age
--|-------|---
1 |Alice |20
2 |Bob |21
3 |Charlie|22
Metadata
Release files for ezpyzy 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ezpyzy-0.2.0.tar.gz | 30.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ezpyzy-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 65.4 kB
Release files / ezpyzy-0.2.0.tar.gz
| Download URL | ezpyzy-0.2.0.tar.gz |
|---|---|
| Size | 30.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea6393c3438dab96e6c539c32bc08f7babbf8021055aa0de7c63ed2647b9a77f
|
|
BLAKE2b-256 checksum How to use checksums |
13f347eb3dd6ac0f2842b8e88e5007a97bdb04bf000fb7b1ab1db7625d5b2826
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.11 Linux/6.0.14-201.fsync.fc36.x86_64
|
Release files / ezpyzy-0.2.0-py3-none-any.whl
| Download URL | ezpyzy-0.2.0-py3-none-any.whl |
|---|---|
| Size | 34.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9893393a17172de866e9cbd960ccf2a28395cfa4f4c0ed59c1772443183a3d78
|
|
BLAKE2b-256 checksum How to use checksums |
164a3544b0a67496ded45d6754e304e7d07623c871fdbc5ca9a7d33edb2ac503
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.11 Linux/6.0.14-201.fsync.fc36.x86_64
|
Security for ezpyzy 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.