Skip to main content

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ekcommon-1.0.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

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

Hashes for ekcommon-1.0.1.tar.gz
Algorithm Hash digest
SHA256 90f9b7da9a699eaf512352c9e44a1b93cc0fc5cd706dff698a4229b9c8110f5e
MD5 bfa071475b7d795b579ce3c3e61d8ebf
BLAKE2b-256 b3ccdefe69f4477d3629ecfecf0ddb396a6037b54d4c6647696a42f63bfb5ded

See more details on using hashes here.

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

Hashes for ekcommon-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b36a339d44dcf2394d2b815bb8df52beb64bae7935dc60dab7c2299e940244f7
MD5 91df03fec1c1c87ab4023f65a77b72fb
BLAKE2b-256 97e0a963a9e02a0aa7ba6cfb5af297fb61d014b69a3f2ce3a4043aefb44222fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page