Skip to main content

Makes printing pretty & easier to follow

Project description

SectiPrint

A custom terminal printing library, making printing prettier. Tries to make tracing which function/object did what easier.


Installation

Install using Pip:

pip install sectiprint

Usage

Basic Printing

To use the sectiprint library, you need to first create a RootPrinter() instance:

import sectiprint

#"name" is arbitrary
#"level" is the minimum level to print
say = sectiprint.RootPrinter(name="main", level=printer.DEBUG)

Once you have a printer instance, you will have access to the default print levels:

  • debug [level=0]
  • info [level=10]
  • warning [level=20]
  • error [level=30]

Each print level has a unique colour. To add your own print level, see Advanced: Adding Custom Print Layers

Now you can call each print layer as required:

say.debug("This is a debug statement")
say("This is the default layer, which is 'info'")

Notice how you can directly call the Printer object? This is because when it's called it passes the message to the default print layer, which is "info".

The default layer can be changed by pointing Printer.default to another print layer:

#This does not affect the print level
say.default = say.error

say("This will print as an error!")

Printing In Other Scopes

The power of this lib comes from how printing inside other scopes works. If you wrap a function or class method with @sectiprint.SubLayer it will add a header to the output that shows the path that was takes to get to the current scope:

import sectiprint

@sectiprint.SubLayer
def funcScope():
	say("This is in another scope!")

say = sectiprint.RootPrinter(name="scopes", level=sectiprint.INFO)

say("This is in the top scope!")
funcScope()

This outputs:

Scope example output


Advanced:

Below are some advanced use cases of the Printer lib

Adding Custom Print Layers

There can be cases where you'll want to add your own print layers. This can be easily done by creating a new PrintLevel object and assigning it to a new attribute in the Root Printer object. You would then call this attribute similar to Printer.info and other calls:

import sectiprint

say = sectiprint.RootPrinter("main", level=5)
say.ok = sectiprint.PrintLayer(
	printer = say,
	level = 5,
	colour = print.GREEN
)

say.ok("This is our new print layer!")

In this case, we create the layer "ok" which prints text as green on layer 5. The GREEN var already exists in the sectiprint library, but you can use ANSI Escape Codes to generate your own colours or designs. For example, pass the string '\033[95m' as the colour to produce purple output!

Sections:

You can add "sections" which prints an additional metadata-like label to help clarify where in the code you are. This is useful when you want to separate your code by logical sections, but don't want them as separate functions

import sectiprint
say = sectiprint.RootPrinter("main")

say("Root print")

say.section("New Section")
say("In the new section")

This produces the following output: Section example output

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

sectiprint-2.0.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file sectiprint-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: sectiprint-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for sectiprint-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8011bc3e2c9e29d7e00462d45ccd9ebd62733f52b0835b5d884faa7c29b38a4
MD5 2ff5344e8d5eceb58525413e3aa801e8
BLAKE2b-256 f742c33ea19e67bb4dea96af500310b5e08a81b334be8cbca025ac5dcfce078a

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