Skip to main content

A collection of miscellaneous functions and utilities for Python and/or Django.

Project description

The Pine Digital Growth Python Package

This package contains a variety of miscellaneous Python helper/utility functions used across different Pine Digital projects.

Installation

Install using pip with:

pip install pppine

What's In The Box?

Python Helpers

Tired of searching StackOverflow for answers to the most basic of Python problems? We've got you covered.

While these helpers may seem random in nature, they've come in handy hundreds of times across multiple Pine Digital products. They're solutions with a personal spin, some with more of a creative touch than others.

Random Generators

  • Generate a string of random numbers of length n.
  • Extract initials out of a person's or organization's name.
  • Create a temporary password that's easier to look at than UUID's.
  • Generate short UUID's. Based on shortuuid, but even shorter.

(Import from pppine.python.generators)

Date, Time, and DateTime Helpers

  • Get the current date and time, but in your local timezone.
  • Greet your users with the proper time of the day. Is it the 'morning', 'afternoon', or 'evening'? Plug in a time object to find out.
  • Get today's date and time, but set the time to midnight.
  • Convert a date object to a datetime object.
  • Parse a datetime from a string or number. Perfect when working with JSON and API's.

(Import from pppine.python.datetime)

Address & Contact Info Helpers

  • Capitalize all the right things in an address the way .title() can't.
  • Format a mailing address nicely, whether you want it in one line or many.
  • Clean an address inputted from a form.
  • Properly capitalize people's names that start with 'Mc', 'Mac', 'de ', and so on.
  • Format a phone number properly based on an inputted country.
  • Check whether an inputted string is an email address.

(Import from pppine.python.contact)

General Helpers

  • Replace a string's character at a specified index without all the extra work.
  • Check whether a file is a certain file type. You never know, file extensions might not always tell a true story.
    • While you're at it, raise a specialized exception if a certain file isn't the file type you want it to be.
  • Get the class name of an object.
  • Check whether a string actually represents a list.
  • Turn a list, dictionary, or any other Python literal into a JSON string, but encode it in base64.
  • Take that base64-converted JSON string and convert it back into a Python literal.
  • Ever see some strings that should be a list? Turn those into an actual list.

(Import from pppine.python.general)

Django Helpers

Make your day-to-day Django tasks easier with these helpers and shorthand notations.

  • Get a comprehensive list of a model's field names.
  • Raise a 404 if one or several URL slugs are nonempty.
  • Get the verbose name of a model instance's field.
  • Shorthand notation to check whether a Django object/query exists.
  • Shorthand notation to return a queried object or None if not found.
  • Reverse a URL namespace with query strings while writing the cleanest code. No f-strings or %s required on your end.
  • Fetch the URL of the page you were redirected from.
  • Update a model instance by dictionary rather than field by field.
  • Convert a Django QueryDict (e.g. request.GET) to a regular dictionary.
  • Safely update an object from another model instance with similar field names.

(Import from pppine.django)

Encoders

  • Get the ultimate encoder for JSON dumps. Very Django-friendly.

Middleware

  • Have Django automatically store an authenticated user's timezone (as saved in their profile) in the current session variables

Miscellaneous

This is more of a data file than a set of helpers, yet still helpful when working with forms that involve countries, provinces, and states.

  • Get a list of tuples for
    • Countries
    • Canadian Provinces
    • US States

e.g.

[
  ('AB', 'Alberta'),
  ('BC', 'British Columbia'),
  ('SK', 'Saskatchewan'),
  ('MB', 'Manitoba'),
  ('ON', 'Ontario'),
  ('QC', 'Quebec'),
  ('NB', 'New Brunswick'),
  ('NS', 'Nova Scotia'),
  ('PE', 'Prince Edward Island'),
  ('NL', 'Newfoundland and Labrador'),
  ('YT', 'Yukon'),
  ('NT', 'Northwest Territories'),
  ('NU', 'Nunavut')
]

(Import from pppine.misc)

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

pppine-1.3.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

pppine-1.3.1-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file pppine-1.3.1.tar.gz.

File metadata

  • Download URL: pppine-1.3.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pppine-1.3.1.tar.gz
Algorithm Hash digest
SHA256 07ab65784f672e620a60529886918f837404c6a0db75ae91a13c032318123b9e
MD5 94b28709d6caf98addf8de14b0e08b01
BLAKE2b-256 616967c05025830a02a5e4a39966435795eaef918f82e7dc309e6161907db79c

See more details on using hashes here.

File details

Details for the file pppine-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: pppine-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pppine-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae8063b2a3d9934e50ca705e4f3e0b8a71e9721c64caa6edc964bfcb4abdc787
MD5 4d79cc4140fb4e10c8ecc5d681c29f3e
BLAKE2b-256 86b5e94604d6b6587346b7063a15882042b6a8350ae00d8bccc28c42c1bd51c9

See more details on using hashes here.

Supported by

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