Lightweight Python library for math, randomness, HTML, Markdown, CSS, and JS rendering — clean and minimal.
Project description
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>
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>
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>
Toast Notifications (auto-fade)
toast(text, color, duration)– white default, fades after 5 seconds(the duration). only text color is supportedtoast_custom(text, color, text_color, duration)– custom color, custom text color, fades after 5 seconds(the duration), default text color is black and color is white. HEX, RGB, RGBA, and HSL are supported.
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 5 seconds unless you provide a custom duration as an argument. The toast_custom() function allows you to customize the color and text color of the toast notification, as well as the duration of the fade-out animation.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytpro-0.2.8.tar.gz.
File metadata
- Download URL: pytpro-0.2.8.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b50dab44835e1741276f123bbfe4145dea93ccd109d447dc6724bc9b967845fb
|
|
| MD5 |
58365085ca9d148de0904ac3a685a9fc
|
|
| BLAKE2b-256 |
27ce307abf6e6e0a7985128fb0c051adb3e910fee35968513709f65e4e88bff1
|
File details
Details for the file pytpro-0.2.8-py3-none-any.whl.
File metadata
- Download URL: pytpro-0.2.8-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cfa81ded6dbafbf9e9befc25515cc63c3a3e49d8b0a19684b388fa1dd6e15f2
|
|
| MD5 |
d8fdf166a8fe3633203bd1b2a600e4c4
|
|
| BLAKE2b-256 |
73da3be50ce227fb4895ef4b94e3f9483da1b7bffbd296e08b2bc437708856e9
|