Common hacks in python.
Project description
common-py
My common Python hacks
Table of Contents
Installation
To install the required dependencies, use:
pip install ekcommon
To use:
from commonpy import *
Usage
Example 1: Handling Exceptions
from commonpy.simpleexceptioncontext import SimpleExceptionContext
callback = lambda e: self._eng.statusChanges.emit(f'Exception in processing {e}')
with SimpleExceptionContext('exception in processing',callback=callback):
ret=self.process_internal(ls)
logging.debug(f"process end {ret}")
return ret
In this example , a callback is called when the exception occurs.
Example 2: Exception Handling with Decorators
@simple_exception_handling(err_description='error in get_symbol_history', return_succ=(None, []), never_throw=True)
@excp_handler(polygon.exceptions.BadResponse, handler=excphandler)
def get_symbol_history(sym, startdate, enddate, iscrypto=False):
# Your code to fetch symbol history here
pass
Example 3: Date and Time Utilities
from commonpy import localize_it, unlocalize_it
import datetime
dt = datetime.datetime.now()
localized_dt = localize_it(dt)
unlocalized_dt = unlocalize_it(localized_dt)
Features
- SimpleExceptionContext: Context manager for handling exceptions with customizable logging and traceback formatting.
- Date and Time Utilities: Functions to localize and unlocalize datetime objects.
- Functional Helpers: Various lambda functions for filtering dictionaries and mapping lists.
Contributing
Contributions are welcome! Please fork this repository and submit a pull request.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ekcommon-1.0.1.tar.gz
(6.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ekcommon-1.0.1.tar.gz.
File metadata
- Download URL: ekcommon-1.0.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90f9b7da9a699eaf512352c9e44a1b93cc0fc5cd706dff698a4229b9c8110f5e
|
|
| MD5 |
bfa071475b7d795b579ce3c3e61d8ebf
|
|
| BLAKE2b-256 |
b3ccdefe69f4477d3629ecfecf0ddb396a6037b54d4c6647696a42f63bfb5ded
|
File details
Details for the file ekcommon-1.0.1-py3-none-any.whl.
File metadata
- Download URL: ekcommon-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b36a339d44dcf2394d2b815bb8df52beb64bae7935dc60dab7c2299e940244f7
|
|
| MD5 |
91df03fec1c1c87ab4023f65a77b72fb
|
|
| BLAKE2b-256 |
97e0a963a9e02a0aa7ba6cfb5af297fb61d014b69a3f2ce3a4043aefb44222fd
|