Skip to main content

project_runpy

https://github.com/crccheck/project_runpy/actions/workflows/ci.yaml/badge.svg?branch=master

Generic helpers I wish existed or am constantly copying into my Python projects. This is also my test project for random processes.

env

Get information about your environment variables.

.get(key, ...)

You can use env.get as a drop-in replacement for os.environ.get. It acts the same but is smarter about types and has extra magic for ENVIRONMENT based settings:

from project_runpy import env

env.get('DATABASE_URL')  # get an environment variable
env.get('DATABASE_URL', 'sqlite:///:memory:')  # provide a default
env.get('DEBUG', True)  # default can be bool
env.get('WORKERS', 10)  # default can be other types too, like int
env.get('DEBUG', True, type_func=bool)  # explicitly get bool

If additional kwargs are specified, they will become the default if ENVIRONMENT matches the key:

from project_runpy import env

env.get('WORKERS', 10, DEV=1)  # if ENVIRONMENT == DEV: default = 1
env.get('DEBUG', FALSE, type_func=bool, TEST=False)  # combine it

.require(key, ...)

If you want to be extra strict/cautious, you can raise an exception if the environment variable was not set by using .require instead of .get.

Demo:

>>> from project_runpy import env
>>> env.require('SHIRTSNSHOES')
ImproperlyConfigured: Environment variable not found: SHIRTSNSHOES

ColorizingStreamHandler

Logging handler that produces colorized console output

Usage:

import logging

from project_runpy import ColorizingStreamHandler

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(ColorizingStreamHandler())

Django:

LOGGING = {

    ...

    'handlers': {

        ...

        'console': {
            'level': 'DEBUG',
            'class': 'project_runpy.ColorizingStreamHandler',
        },
    },

    ...

}

ReadableSqlFilter

A logging filter designed to make the django.db.backends output more readable in local dev. This is an alternate to Django Debug Toolbar’s SQL panel (which, you should be using too) and adds feedback for queries outside HTML. This will slow down your dev server, but it’s a tradeoff for getting faster feedback for optimizing your queries.

Django compatibility: Django >= 2.0

Turns:

(0.002) SELECT "tx_elevators_building"."id", "tx_elevators_building"."elbi",
"tx_elevators_building"."name_1", "tx_elevators_building"."name_2",
"tx_elevators_building"."address_1", "tx_elevators_building"."address_2",
"tx_elevators_building"."city", "tx_elevators_building"."zip_code",
"tx_elevators_building"."county", "tx_elevators_building"."owner",
"tx_elevators_building"."contact", "tx_elevators_building"."latitude",
"tx_elevators_building"."longitude" FROM "tx_elevators_building" LIMIT 21;
args=()

Into:

(0.002) SELECT...FROM "tx_elevators_building" LIMIT 21

And when you have many queries, they all line up nicely in your terminal.

To install, edit your Django settings:

LOGGING = {
    ...
    'filters': {
        'readable_sql': {
            '()': 'project_runpy.ReadableSqlFilter',
        },
    },
    'loggers': {
        'django.db.backends': {
            'filters': ['readable_sql'],
            ...
        },
    },
    ...
}

About

Inspired by dj-settings-helpers, ansistrm.py, and tornado’s define.

Metadata

Release files for project-runpy 1.1.2

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

Source distribution (sdist)

Source distribution for project-runpy 1.1.2
File Size Uploaded Provenance Actions
project_runpy-1.1.2.tar.gz 17.4 kB Without provenance Details for project_runpy-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for project-runpy 1.1.2
File Interpreter ABI Platform Actions
project_runpy-1.1.2-py3-none-any.whl Python 3 none any Details for project_runpy-1.1.2-py3-none-any.whl

Total release size: 27.6 kB

Release files / project_runpy-1.1.2.tar.gz

Download URL project_runpy-1.1.2.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
898f64d4417be57e04df6143630e2694b79347576a35bbc8d02b30812b7d7f1f
BLAKE2b-256 checksum
How to use checksums
e45d593a226a1b822f8959443d94638c22e33ec77fae92466bcf3129c3d47f79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / project_runpy-1.1.2-py3-none-any.whl

Download URL project_runpy-1.1.2-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
707e66b0215139aff15d85c16df87d8620d09d31bd55cd1bb7444c093151ef3a
BLAKE2b-256 checksum
How to use checksums
ac859f4e72c42a231bc87573d43407e2ba89daef11f33266ad2823173a3f173f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.5

Security for project-runpy 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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