Skip to main content

🔧 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')

Metadata

Release files for utilita 1.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for utilita 1.0.14
File Size Uploaded
utilita-1.0.14.tar.gz 36.1 kB Details

Release files / utilita-1.0.14.tar.gz

Download URL utilita-1.0.14.tar.gz
Size 36.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a01f6c2f683bd76104328f54b291bedbefe30db06a4b9abdf09207987457c52f
BLAKE2b-256 checksum
How to use checksums
1273f0231342195e7f4bf0c2fa4dfbfe37ee48f7a5a7efce1414d8ff1789f34b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

1.0.14 This release

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page