Skip to main content

a utility library

Project description

🔧 utilita

PyPI version Build Status Coverage Status

a utility library

Quick install

pip install utilita

Basic usage

[decent pitch]. Let's dive in.

Out-of-the-box you get some stuff you can do with utilita:

import datetime
from utilita import date_fns

w52d7 = datetime.date(2020,12,27)
w53d1 = datetime.date(2020,12,28)

date_fns.is_in_leap_week(w52d7) # => False
date_fns.is_in_leap_week(w53d1) # => True

date_fns.days_since_same_date_last_year(w52d7) # => 364 (days in non-leep-week years)
date_fns.days_since_same_date_last_year(w53d1) # => 371 (days in leep-week years)

more about ISO 8601 leap weeks: https://en.wikipedia.org/wiki/ISO_week_date

Examples:

Working with sendgrid

from utilita import sendgridhelper as sghelper

eml = sghelper.SendgridHelper(
    sendgrid_api_key=os.getenv('sendgrid_key'), 
    from_email={"email": 'test@example.com', "name": "Test BI"}
    )

email_subject = f'Testing email from Test BI sent on {int(datetime.datetime.now().timestamp())}'
email_body = '''
    <html>
    <body>
    Hello, <br />
    This is a test email<br />
    <i>Derp</i>
    <br><br>
    Thank you,<br>
    Test BI
    </body>  
'''

eml.config_email(subject=email_subject,
                 body=email_body,
                 recipients={
                     "to": "user1@example.com, user2@example.com",
                    #  "cc": "test@example.com",
                    #  "bcc": "bcc@example.com"
                 }
                 )

# Attach excel files from disk:
eml.attach_excel_file_from_path('files/1.xlsx')
eml.attach_excel_file_from_path('files/2.xlsx')

# attach dataframe as a csv file.
import pandas as pd

headers = ['date', 'department', 'sales']
data = [
    ('2023-12-20', 'Bread', 100),
    ('2023-12-20', 'Deli', 1),
    ('2023-12-20', 'Frozen', 400)
]
df = pd.DataFrame(columns=headers, data=data)
# compressed will compress to a zip file.
eml.attach_single_df_as_csv(df=df, df_filename='sales.csv', compressed=True)

# Send email
eml.send_email()

Example for working with excel workbooks

from utilita import excel
import pandas as pd
import openpyxl as xl

wb = xl.load_workbook(filename='files/tables.xlsx')

# Load dataframe into an excel table:
df = excel.excel_table_to_df(wb=wb, sheet_name='Sheet1', table_name='Table2')

# Get data from an excel table into a dataframe:
# Export table into excel workbook
headers = ['date', 'department', 'sales']
data = [
    ('2023-12-20', 'Bread', 100),
    ('2023-12-20', 'Deli', 1),
    ('2023-12-20', 'Frozen', 400)
]
df = pd.DataFrame(columns=headers, data=data)

excel.df_to_excel_table_resize(df=df, wb=wb, sheet_name='Sheet1', table_name='Table2')

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

utilita-1.0.14.tar.gz (36.1 kB view details)

Uploaded Source

File details

Details for the file utilita-1.0.14.tar.gz.

File metadata

  • Download URL: utilita-1.0.14.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for utilita-1.0.14.tar.gz
Algorithm Hash digest
SHA256 a01f6c2f683bd76104328f54b291bedbefe30db06a4b9abdf09207987457c52f
MD5 2fed54fa1549d2d21b42c16fd284e971
BLAKE2b-256 1273f0231342195e7f4bf0c2fa4dfbfe37ee48f7a5a7efce1414d8ff1789f34b

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