common-py
My common Python hacks
Table of Contents
Installation
To install the required dependencies, use:
pip install ekcommon
To use:
from ekcommon import *
or
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.
Metadata
Release files for ekcommon 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ekcommon-1.0.2.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ekcommon-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.6 kB
Release files / ekcommon-1.0.2.tar.gz
| Download URL | ekcommon-1.0.2.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
abb4f9fa35affc4a4f39588fed9b17409a8185afcce9ca40e05928aa6f0df9ed
|
|
BLAKE2b-256 checksum How to use checksums |
079fa6b3a9ad4ba529b06372edf5ac01430708ecad974f85bcffc8da76f27d5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|
Release files / ekcommon-1.0.2-py3-none-any.whl
| Download URL | ekcommon-1.0.2-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fb75bdae80d3162173886a3a44446553efbcd6732b51bb509597b74c7446ad9
|
|
BLAKE2b-256 checksum How to use checksums |
496426ace9597dd1d0737c08ce09c69470ead63629b33083930467df747757ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|