Skip to main content

A simple Python tools package by Ibrahim Akhlaq

Project description

pytpro logo

Pytpro

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.

API REFERENCE

🚀 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;
    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;
    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>
  • <style>

button { background-color: red; color: white; } </style> Hello World!

{javascript is not supported in PYPI}

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

🖥️ 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
 _______  ___    ___ ________  _______    _________    ________
|   ___  \\  \  /  /|__    __||   ___  \ |   ___   | /  ______  \
|  |___|  |\  \/  /    |  |   |  |___|  ||  |___|  ||  /      \  |
|   _____/  \    /     |  |   |   _____/ |    ____/ |  |      |  |
|  |         \  /      |  |   |  |       |    \___  |  |      |  |
|  |         |  |      |  |   |  |       |  |\__  \_|  \______/  |
|__|         |__|      |__|   |__|       |__|   \____\ ________ /

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.6.tar.gz (13.4 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.6-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytpro-0.2.6.tar.gz
  • Upload date:
  • Size: 13.4 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.6.tar.gz
Algorithm Hash digest
SHA256 dba01b9b94b99179e3bdcae2622beaeb72a3b925750ec418f08b939138df5e3a
MD5 8b0c106ebee00db56653f6406fe872bb
BLAKE2b-256 71e7a1a8fd8986795889791c9d4b71eba4408a3bac311766e83763a9b8330497

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytpro-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 11.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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c04fef8b01a1cdef6f71ef78b1ec06a7dcfd883ff715ec67f738aceec72943d2
MD5 c5a58a621cd9cecab30feb75bae2016f
BLAKE2b-256 66b805c89abe0f13e387b717809444981e417e672eec3b12e4c82bd9a2528a52

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