Skip to content

Commit b7120b7

Browse files
committed
Update to 0.0.7 - Update Readme, add examples
1 parent 1f39466 commit b7120b7

File tree

11 files changed

+520
-62
lines changed

11 files changed

+520
-62
lines changed

README.md

Lines changed: 212 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
# lazyops
2-
A collection of Lazy Python Functions that aim to balance functionality, performance, and utility.
1+
# Lazy Op(eration)s or lazyops
32

4-
**Why**
5-
After the nth time of rewriting and/or copying existing functions, I figured it was easier to maintain them all in a single library.
6-
7-
### Dependencies
8-
- Python 3.7+
9-
- [pysimdjson](https://github.com/TkTech/pysimdjson): simdjson's C++ JSON parser can handle 2 GB/s+ of throughput, allowing millions of JSON docs to be parsed per sec/per core.
10-
- [fileio](https://github.com/trisongz/fileio): My personal file lib that wraps many useful I/O ops, allowing you to work with cloud objects faster, and in less lines of code.
11-
- [aiohttp](https://github.com/aio-libs/aiohttp): Enables async http calls, maximizing throughput for web requests.
12-
- [dateparser](https://github.com/scrapinghub/dateparser): Makes working with natural query dates easier `5 days ago`.
13-
- [six](): Enables functionality in `retryable` decorator.
3+
A collection Python modules and submodules focused on balancing functionality,
4+
performance, utility and Lazyiness.
145

156
---
167

@@ -19,11 +10,149 @@ Install directory from pypi
1910

2011
`pip install --upgrade lazyops`
2112

13+
Install from Github
14+
15+
`pip install --upgrade git+https://github.com/trisongz/lazyops`
16+
17+
---
18+
19+
## The `LazyOps` Philosophy
20+
21+
**Minimalistic**: Minimal External Libraries/Dependencies. Minimal imports.
22+
23+
**Automatic and JIT**: Use a `Just-in-Time` approach for loading dependencies.
24+
Auto-Install external libraries `as needed` for submodules.
25+
26+
**Minimal Lines of Code to Accomplish Goal**: Tries to handle as many use-cases
27+
as possible with minimal limitations on end-user in how its defined.
28+
29+
**High Performant**: Carefully selected, battle-tested libraries providing the
30+
highest level of performance, while consuming as little resources as needed (RAM)
31+
or scale to as many resources allowed (Threads)
32+
33+
**(Mostly) Filesystem Agnostic**: Cloud Object _(GCS atm)_ or Local files are
34+
supported automatically.
35+
36+
**Reduce Redudancy**: Handle redundant user logic automatically unless explicitly
37+
defined.
38+
39+
**Object Oriented**: Clean Classes and Objects allow for out-of-the-box usage or
40+
for customizability.
41+
42+
**Builtin Async**: If it needs to be done fast or many times, `async` should probably
43+
be available.
44+
45+
Counter-intuitively, building `lazyops` was anything-but-lazy. To (try) to accomplish
46+
all the above, every class, object, or function had to be designed to be written once
47+
with the idea that they can stand on their own for as many use cases as possible.
48+
49+
This project is a work in process and will continue to evolve over time.
50+
51+
52+
---
53+
54+
### The Minimal Dependencies (and rationale)
55+
56+
- Python 3.7+
57+
- [pysimdjson](https://github.com/TkTech/pysimdjson): simdjson's C++ JSON parser can
58+
handle 2 GB/s+ of throughput, allowing millions of JSON docs to be parsed per sec/per core.
59+
- [fileio](https://github.com/trisongz/fileio): My personal file lib that wraps many
60+
useful I/O ops, allowing you to work with cloud objects faster, and in less lines of code.
61+
- [aiohttp](https://github.com/aio-libs/aiohttp): Enables async http calls, maximizing
62+
throughput for web requests.
63+
- [dateparser](https://github.com/scrapinghub/dateparser): Makes working with natural
64+
query dates easier `5 days ago`.
65+
- [six](): Enables functionality in `retryable` decorator.
66+
2267
---
2368

24-
### API Usage
69+
### LazyOps API Usage
70+
71+
- [LazyOps Core](#lazyops-core)
72+
- [LazyClassses](#lazyclasses)
73+
- [LazyAPI](#lazyapi)
74+
- [LazyDatabase](#) - WIP
75+
- [LazyRPC](#) - WIP
76+
- [LazyIO](#) - WIP
77+
- [LazySources](#) - WIP
78+
- [LazyBloom](#) - WIP
79+
80+
81+
---
82+
83+
#### LazyOps Core
84+
85+
LazyOps' Core APIs that can be used to handle most common functionalities that can often
86+
be redundant to constantly define.
87+
88+
**Utilities**
89+
90+
Useful functions that speed up development.
91+
92+
```python
93+
from lazyops import lazy_init
94+
95+
# Lazily initialize Tensorflow and ensure Tensorflow == 2.5.0
96+
# before importing
97+
# tf can now be used as you would if you called `import tensorflow as tf`
98+
99+
tf = lazy_init('tensorflow==2.5.0', 'tensorflow')
100+
physical_devices = tf.config.list_physical_devices('GPU')
101+
print("Num GPUs:", len(physical_devices))
102+
103+
from lazyops import get_logger
104+
105+
# This will create a logger that handles stderr / stdout for Notebook envs
106+
# This logger is also threadsafe as it creates a threadlock to prevent duplication
107+
108+
logger = get_logger('MyLib', submodule = __file__)
109+
110+
from lazyops import timed_cache, retryable, lazymultiproc, lazyproc
111+
112+
def get_dataset(*args, **kwargs):
113+
# do stuff
114+
return dataset
115+
116+
# default num_processes = CPU Cores
117+
@lazymultiproc(dataset_callable=get_dataset, num_procs=10)
118+
def process_dataset(item, *args, **kwargs):
119+
# do stuff
120+
return item
121+
122+
# LRU Cache with timed expiration
123+
@timed_cache(seconds=60, maxsize=600)
124+
def load_dataset(*args, **kwargs):
125+
# do stuff
126+
return dataset
25127

26-
**Time/Timer/Date Functionalities**
128+
# turns this function into a thread.Thread function, returning thread obj.
129+
@lazyproc(name = 'monitoring_x', start = True, daemon = False)
130+
def monitor_x(*args, **kwargs):
131+
# do stuff
132+
return
133+
134+
# Retries this function call
135+
@retryable(stop_max_attempt_number = 5)
136+
def call_api(*args, **kwargs):
137+
# do stuff
138+
return response
139+
140+
# Utils for running shell commands and cloning repo projects
141+
from lazyops import run_cmd, clone_repo
142+
143+
# clones lazyops to relative /cwd/lops.
144+
# if add_to_syspath = True, will append repo path to $PATH
145+
clone_repo(repo='https://github.com/trisongz/lazyops', path='lops', absl=False, add_to_syspath=True)
146+
147+
# returns system response of `df -h` as string
148+
res = run_cmd('df -h')
149+
150+
```
151+
152+
153+
**Time/Timer/Date**
154+
155+
Handle time, timers and datetime mostly automatically.
27156

28157
```python
29158
import time
@@ -63,13 +192,17 @@ timer.stop_timer('benchmark_1')
63192
timer.timers()
64193

65194
```
195+
---
66196

67-
**Lazyclass Functionalities** [WIP]
197+
#### LazyClasses
68198

69-
*To Do:*
70-
- Implement `many=True` found in `dataclasses_json`
199+
LazyClasses are an extension of `dataclasses`, building on top of [fastclasses-json](https://github.com/cakemanny/fastclasses-json),
200+
and inspired by heavy usage of [dataclasses-json](https://github.com/lidatong/dataclasses-json). `LazyClass` utilizes `simdjson` as
201+
the default `JSON` serializer for faster performance.
71202

72203

204+
Example Usage:
205+
73206
```python
74207
from dataclass import dataclass
75208
from lazyops import lazyclass
@@ -113,12 +246,24 @@ hero_config = {
113246
}
114247

115248
Batman = NewHero.load(hero_config)
249+
# Or directly
250+
Batman = NewHero(**hero_config)
116251

117252
```
118253

119-
**LazyAPI Functionalities**
254+
**Roadmap**
255+
- Implement `many=True` found in `dataclasses_json`
256+
257+
---
258+
259+
#### LazyAPI
260+
261+
Define and Create API Endpoints as a Class with just a `Dict` with
262+
builtin `async` support. API Models are compiled `JIT` with endpoints
263+
set as the `LazyAPI` class attribute, enabling them to be called as
264+
a function.
120265

121-
Build JIT API Models from a JSON / Dict, leveraging lazyclass
266+
Example Usage
122267

123268
```python
124269
from lazyops import LazyAPI
@@ -158,5 +303,53 @@ res = api.predict(data='api model task data ...')
158303
print(res)
159304

160305
```
306+
---
307+
308+
#### LazyRPC
309+
310+
WIP
311+
312+
---
313+
314+
#### LazyDatabase
315+
316+
WIP
317+
318+
---
319+
320+
#### LazyIO
321+
322+
WIP
323+
324+
---
325+
326+
#### LazySources
327+
328+
WIP
329+
330+
---
331+
332+
#### LazyBloom
333+
334+
WIP
335+
336+
---
337+
338+
339+
#### Credits & Acknowledgements
340+
341+
`LazyOps` heavily builds & borrows on the work of others in many instances.
342+
In order to maintain minimalism and not have unneeded libraries added to dependencies,
343+
some parts of the library have been added into `LazyOps`. The original works often inspired
344+
new ideas from studying the code and are definitely worth checking out.
345+
346+
347+
In no particular order:
348+
349+
- [retrying](https://github.com/rholder/retrying)
350+
- [fastapi-jsonrpc](https://github.com/smagafurov/fastapi-jsonrpc)
351+
- [fastclasses-json](https://github.com/cakemanny/fastclasses-json)
352+
- [dataclasses-json](https://github.com/lidatong/dataclasses-json)
353+
- [gdelt-doc-api](https://github.com/alex9smith/gdelt-doc-api)
161354

162355
TBC
File renamed without changes.

0 commit comments

Comments
 (0)