Skip to main content

Lightweight Python library for math, randomness, HTML, Markdown, CSS, and JS rendering — clean and minimal.

Project description

pytpro logo

pytpro heading

pytpro is a lightweight Python package by Ibrahim Akhlaq that provides powerful utility functions for math, randomness, and HTML rendering. It's clean, minimal, and built to feel like magic.

🖥️ Example Usage

import pytpro

pytpro.add(2, 3)
pytpro.square(6)
pytpro.pi()
pytpro.htmlcssjs("<h1>Hello!</h1><p>This is raw HTML.</p>")

🖥️ Instructions to install:

To install locally from your project directory, open PowerShell or terminal and run:

pip install pytpro

API REFERENCE

  • disclaimer: Some of the output examples in the API reference cannot be rendered in PYPI, so screenshots of the actual results were provided. Keep in mind that the output may differ slightly from the actual results, as I had to resize the images in some cases.

🚀 Features

➕ Math Functions:

  • add(a, b):

The add() function takes two numbers a and b and returns their sum.

  • subtract(a, b):

The subtract() function takes two numbers a and b and returns their difference a-b.

  • multiply(a, b):

The multiply() function takes two numbers a and b and returns their product.

  • divide(a, b):

The divide() function takes two numbers a and b and returns their quotient a/b.

  • modulus(a, b):

The modulus() function takes two numbers a and b and returns the remainder of a/b.

  • floordivision(a, b):

The floordivision() function takes two numbers a and b and returns the largest integer less than or equal to a/b.

  • square(a) / cube(a):

These functions return the square or cube (respectively) of a number a.

  • squareroot(a) / cuberoot(a):

These functions return the square root or cube root (respectively) of a number a.

  • absolutevalue(a):

The absolutevalue() function returns the absolute value of a number a.

  • roundoff(a):

The roundoff() function rounds a number a to the nearest integer.

  • exponent(a, b) / power(a, b)

These functions return a raised to the power of b.They are the same functions but they have different names for convenience.

🔢 Random Number Generators

  • randint(start=0, end=100):

The randint() function generates a random integer between start and end (inclusive). The default value is 0 to 100.

  • randfloat():

This function (randfloat()) generates a random floating-point number between 0 and 1. It requires no parameters or arguments, and if you want to generate a random float in a specific range, you can use the randomfloatpositive(start, end) or randomfloatnegative(start, end) functions. Inputting an argument or parameter could result in errors.

  • randomintpositive(start, end, step=1):

The function randomintpositive() generates a random integer between start and end (inclusive) with a step size of step. The return value of this function will always be a positive value, whether the input is positive or negative.

  • randomintnegative(start, end, step=1):

The function randomintnegative() generates a random integer between start and end (inclusive) with a step size of step. The only difference between this function and the randomintpositive() function is that the generated integer will return a negative value, whether the input is positive or negative.

  • randomfloatpositive(start, end):

The function randomfloatpositive() generates a random floating-point number between start and end (inclusive). Just like the randomintpositive() function, the return value of this function will always be a positive value, whether the input is positive or negative.

  • randomfloatnegative(start, end):

The function randomfloatnegative() generates a random floating-point number between start and end (inclusive). Just like the randomintnegative() function, the return value of this function will always be a negative value, whether the input is positive or negative.

  • randomfloat(start, end):

The function randomfloat() generates a random floating-point number between start and end (inclusive).

📐 Trigonometry & Logs

(1) sine(x)
(2) cosine(x)
(3) tangent(x)
(4) arctangent(x)
(5) log_base_2(x)
(6) log_base_10(x)
(7) natural_log(x)

The functions above return the sine, cosine, tangent, arctangent, log base 2, log base 10, and natural logarithm of a number x respectively.


📏 Constants

`pi()`, `e()`, `goldenratio()`, `tau()`
`speedoflight()`, `planckconstant()`, `gravitationalconstant()`
`electronmass()`, `protonmass()`, `neutronmass()`
`electronvolt()`, `joule()`, `kilojoule()`, `megajoule()`, `gigajoule()`, `terajoule()`, `petajoule()`, `exajoule()`

The functions above return the value of their respective constants. Note that the functions have no parameters or arguments. If any parameter or argument is provided, it could result in errors that are extremely hard to diagnose.


HTML RENDERING

write(text)

You can use the write() function to render text.

Example

import pytpro as py
py.write("Hello World!")

Output

<p>Hello World!</p>
  • Hello World!

title(text)

You can use the title() function to render a title as HTML text.

Example

import pytpro as py
py.title("Hello World!")

Output

<h1>Hello World!</h1>
  • Hello World!

header(text)

You can use the header() function to render a header as HTML text.

Example

import pytpro as py
py.header("Hello World!")

Output

<h2>Hello World!</h2>
  • Hello World!

subheader(text)

You can use the subheader() function to render a subheader as HTML text.

Example

import pytpro as py
py.subheader("Hello World!")

Output

<h3>Hello World!</h3>
  • Hello World!

caption(text)

You can use the caption() function to render a caption as HTML text.

Example

import pytpro as py
py.caption("Hello World!")

Output

<p style='font-size: 0.9em; color: gray;'>Hello World!</p>

Hello World!

htmlcssjs(html_fragment)

You can use the htmlcssjs() function to render raw HTML, CSS, and Javascript code.

Example

import pytpro as py
py.htmlcssjs("""
<style>
button {
    background-color: red;
    border: none;
    border-radius: 4px;
    padding: 15px 32px;
    color: white;
}
</style>
<button onclick='click()'>Hello World!</button>
<p id="output"></p>
<script>
  const output = document.getElementById('output');
  function click() {
    output.innerHTML = 'Hello World!';
  }
</script>
""")

Output

<style>
button {
    background-color: red;
    border: none;
    border-radius: 4px;
    padding: 15px 32px;
    color: white;
}
</style>
<button onclick='click()'>Hello World!</button>
<p id="output"></p>
<script>
  const output = document.getElementById('output');
  function click() {
    output.innerHTML = 'Hello World!';
  }
</script>

button

Alert Boxes

alertbox_red(text)

alertbox_green(text)

alertbox_blue(text)

alertbox_yellow(text)

alertbox_purple(text)

alertbox_orange(text)

alertbox_pink(text)

alertbox_cyan(text)

alertbox_lime(text)

alertbox_brown(text)

alertbox_gray(text)

alertbox_black(text)

You can use the alertbox_*() functions to display alert boxes. Each function takes a text argument, which is the message to be displayed in the alert box. The alert boxes have different colors and styles, making them visually distinct from each other.

Example

import pytpro as py
py.alertbox_red("Hello World!")

Output

    <div style='
        padding: 16px;
        margin: 10px 0;
        background-color: #fdecea;
        color: #b00020;
        border-left: 6px solid #b00020;
        border-radius: 4px;
        font-family: sans-serif;
    '>
        Hello World!
    </div>

pypi

Toast Notifications (auto-fade)

  • toast(text) – white default
  • toast_red(text)
  • toast_green(text)
  • toast_blue(text)
  • toast_black(text)
  • toast_pink(text)

You can use the toast() function to display a toast notification with a default color of white. The function takes a text argument, which is the message to be displayed in the toast notification. The toast notification will automatically fade out after a few seconds.

Disclaimer: This feature is experimental and may not work as expected in all cases. It is not recommended to use this yet, as it is still being developed and may have bugs or issues. Fixes will be applied in future updates.


Markdown Preview

markdown(text)

You can use the markdown() function to display markdown text.

Example:

import pytpro as py
py.markdown("""
# Hello World!
This is a paragraph with **bold**, *italic*, and `inline code`.
""")
<h1> Hello World!</h1>
<p>This is a paragraph with <strong>bold</strong>, <em>italic</em>, and <code>inline code</code>.</p>
  • Hello World!

    This is a paragraph with bold, italic, and inline code.

For more information about Markdown formatting and its syntax, see the Markdown documentation, cheat sheet, basic syntax, or extended syntax.

Pytpro

 _______  ___    ___ ________  _______    _________    ________
|   ___  \\  \  /  /|__    __||   ___  \ |   ___   | /  ______  \
|  |___|  |\  \/  /    |  |   |  |___|  ||  |___|  ||  /      \  |
|   _____/  \    /     |  |   |   _____/ |    ____/ |  |      |  |
|  |         \  /      |  |   |  |       |    \___  |  |      |  |
|  |         |  |      |  |   |  |       |  |\__  \_|  \______/  |
|__|         |__|      |__|   |__|       |__|   \____\ ________ /

version:0.3.0

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

pytpro-0.2.7.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

pytpro-0.2.7-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file pytpro-0.2.7.tar.gz.

File metadata

  • Download URL: pytpro-0.2.7.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pytpro-0.2.7.tar.gz
Algorithm Hash digest
SHA256 4ef047afcd0681de682de29f05d8e2adf4e097eca6f33befb60f99e1aa15233d
MD5 fd5f15d8a7b400000d4aa513c9adb3d8
BLAKE2b-256 87aaa441eef4ab163e009aa3b3164f71c69c30f6ca8095d2804882e3f758e030

See more details on using hashes here.

File details

Details for the file pytpro-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: pytpro-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pytpro-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f7e74233043ae755dcbcf8ce368793b046c6d0ccdc56d8d93854105e4ae8dbad
MD5 456c7259d4a985036c2376dbc535015f
BLAKE2b-256 d3c7b8262571c284fee4f1140328a3f4f1e29f772e25ab2337e274cb27c8fc58

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