Skip to main content

Pysha

Pysha Micro Framework. For Doing Something Beautiful In Python :)

You can See examples of pysha in Examples directory.

Installation

Just Run This Command :

pip install pysha

Usage

Add This At First Of Your Code :

from pysha import *

Examples

  • Switch-Case
Switch(var).cases({
    Case(5):
        lambda: (
            print("Number Wasnt 5.") ,
            print(2)
        ),
    Case(10):
        lambda: (
            print("Number Was 10 !") ,
            print(3)
        ),
    Case(15):
        lambda: (
            print("Number Wasnt 15.") ,
            print(4)
        ),
    Case(20):
        lambda: (
            print("Number Wasnt 20.") ,
            print(5)
        ),
    Default:
        lambda:(
            print("Finish")
        )
})
  • Interface
@interface
class Car:
    name = None
    speed = 0

    def setSpeed(self,speed):
        pass


@interface(Car)
class Tesla:
    name = "Tesla"
    speed = 0

    def setSpeed(self, speed):
        self.speed = speed

    def getSpeed(self):
        return self.speed


@interface(Car) # Wrong Because setSpeed Is Not Defined. ( Will Raise Error )
class BMW:
    name = "BMW"
    speed = 0

@interface(Car) # Wrong Because setSpeed Is Not Defined Right ( Parameter Problem ). ( Will Raise Error )
class Benz:
    name = "Benz"
    speed = 0

    def setSpeed(self):
        pass


myCar = Tesla()
myFriendCar = BMW() # Raises Error Because BMW Does Not Have setSpeed Method.
myCar.setSpeed(100)
# Rest Of Your Code...
  • Pysha Types
# PyshaString
a = PyshaString("some string")
print(a << " and something else") # "some string and something else"
print(a - "some") # " string"
print(a.replace_dict({"some":"one","string":"int"})) # "one int"

# PyshaDict
b = PyshaDict({"name":"Arshia"})
print(~b) # {"Arshia":"name"}
print(b - "name") # {}
print(~b.get("Arshia")) # "name"

# PyshaList
c = PyshaList(["name","hay"])
print(c.count_deep("a")) # 2
print(c >> 1) # ["hay","name"] thats just right shift
print(c) # [ name, hay ]
print(c + ["yo"]) # ["name","hay","yo"]

  • One line Conditions
a = command()
print(a.condition("i > j ? i:j",i=10,j=20))

# Or this way
print(Cond(i>j)(i,j))
  • One line loop
a = command()
a.loop("<i:2,j:3>{hey thats _j_ index in _i_ column}",mode="i")
# "p" mode is for just printing and "i" mode is for get input.

# Or this way
ans = Loop(2,3)("Whats number [_1_][_2_] ?")
# This will automatically loop through an array[2][3] and get input from it and will return answer
  • CrossPlatformer ( You can make cross platform apps easier )
cp = CrossPlatformer()
cp["clearScreen"] = {"windows": "cls", "linux": "clear","mac":"clear"}
cp["listFiles"] = {"windows": "dir", "linux": "ls","mac":"clear"}

# rest of your code...

print(cp["clearScreen"]) # automatically returns value depends on your platform.
  • Cool Decorators
# just for no argument functions that runs once without calling it
@once
def init():
    print("Initializing")

# ignore and continue the process in case of ZeroDivisonError ( you can set '*' to ignore everything )
@ignore(exceptions=[ZeroDivisionError])
def test():
    print(1 / 0)

# retry the function in case of ZeroDivisonError until 3 times ( you can set '*' to ignore everything )
@retry(count=3, exceptions=[ZeroDivisionError])
def calculation():
    print(1 / 0)
  • Multi-Layer Ecnryption/Decryption
variable = make_enc(alg=[Algorithms.XOR,Algorithms.Base64],key=10)
variable.enc("Hello")
variable.dec("Qm9mZmU=")
  • Colored User-Input
name = colorprompt(colorize("(Fore.GREEN)[Enter Your Name :] "),char_color=fore["cyan"])
password = passprompt(colorize("(Fore.GREEN)[Enter Your Password :] "),mask_color=fore["cyan"])
pp(name)
  • Text Options
banner("text",font="3-D") # make cool text with setted font ( uses pyfiglet and figlet fonts )
rect("Hello\nI'm Arshia") # all characters and colors even distances can be customized too
# Customizing helps will be added on wiki

l(('-', Fore.CYAN), count=50) # Draw a line with specific character and color

# and some other cool things :)
  • Customizable PercentPrinter
a = PercentPrinter(chars=30,pass_color=fore["green"],loading_color=fore["cyan"])
a.config(char_ok='@',char_loading='-')
a.show(char_ok='%',char_loading='`') # Overwrite Config But Not Changes It.
a.increase(50)
a.finish(show=False)
print("Done")
  • Save And Load Variables With Encryption
# Save 2 Variables
Save("test.txt",name="Arshia",age=19)()

# Load Those 2 Variables
import sys
this = sys.modules[__name__]

Load("test.txt")(this)

After Load Variables, They Are Accessable In Your Code !

And Lots Of Beautiful Things :)

You Can Look At More Examples Or Docs To See More :)

Release files for pysha 0.1.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 pysha 0.1.3.1
File Size Uploaded
pysha-0.1.3.1.tar.gz 65.6 kB Details

Built distribution (wheel)

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

Total release size: 120.1 kB

Release files / pysha-0.1.3.1.tar.gz

Download URL pysha-0.1.3.1.tar.gz
Size 65.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a7c3b6c940a7acb9280be4dd4bdcb5a15766bdf6fc3426f171aea2e2472c26fe
BLAKE2b-256 checksum
How to use checksums
7c33862fb8fdc531b44af29c99e59b8fb17509e1017466da212ae834613d4065
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.0

Release files / pysha-0.1.3.1-py3-none-any.whl

Download URL pysha-0.1.3.1-py3-none-any.whl
Size 54.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c27af1280b1542438c101493693981f79a487078a0a3e10d35826084351e263
BLAKE2b-256 checksum
How to use checksums
6046bcad6f0221be2a2bbf50a42f5ec34de40013c2ccad145b74c59776fd7761
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.1.3.1 This release

2 release files

0.1.3

2 release files

0.0.2

2 release files

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