Skip to main content

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.1

Metadata

Release files for pytpro 0.3.1

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

Source distribution (sdist)

Source distribution for pytpro 0.3.1
File Size Uploaded Provenance Actions
pytpro-0.3.1.tar.gz 14.7 kB Without provenance Details for pytpro-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytpro 0.3.1
File Interpreter ABI Platform Actions
pytpro-0.3.1-py3-none-any.whl Python 3 none any Details for pytpro-0.3.1-py3-none-any.whl

Total release size: 27.4 kB

Release files / pytpro-0.3.1.tar.gz

Download URL pytpro-0.3.1.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f5f96178e4ddf7d6da6585679bebee63b89923c4a8fd5cdad4132ccdc60b5814
BLAKE2b-256 checksum
How to use checksums
689086bd5c2edeae5c9b6c76ce1dff1c07592cd0d90d9f9f1823a61fb8322b4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / pytpro-0.3.1-py3-none-any.whl

Download URL pytpro-0.3.1-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
917cfea667ff283a0e23fd445142e84476abd09e7c46e70588fd37374db022fb
BLAKE2b-256 checksum
How to use checksums
f8a47f447adc11d1f2f6e5b02e45a0f1c991184cdbdba1681f092ef413acce22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for pytpro 0.3.1

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