Skip to main content

Spaceworld is a new generation Cli framework for convenient development of your teams written in Python 3.12+ with support for asynchronous commands

Project description

SpaceWorld

Python License Package version PyPI Downloads

Spaceworld is a new generation Cli framework for convenient development of your teams written in Python 3.12+ with support for asynchronous commands

Source Code: https://github.com/Binobinos/SpaceWorld documentation: https://binobinos.github.io/Spaceworld

The key features are:

  • Highest speed: For high-load applications
    • Huge flexibility: The ability to customize handlers, commands, and modules
    • Code simplicity: With all the advantages, your code remains as simple as possible
    • Support for *args, **kwargs
    • Extended type annotations: Use new annotations like Annotated, Literal, Union, and others
    • Support for Validators and transformers in annotations

Install Spaceworld

The first step is to install SpaceWorld.

First, make sure you create your virtual environment, activate it, and then install it, for example with:

pip install spaceworld

Example

The simplest example

import spaceworld


def main():
    print("Hello World")


if __name__ == '__main__':
    spaceworld.run(main)

Copy that to a file main.py.

Test it:

$ python main.py main

Hello World

$ python main.py main --help

Usage: main [ARGS] [OPTIONS]  
None documentation

Options:
  --help - Displays the help on the command

One Cli argument

This output for the function looks very simple. Let's create a new function. hello, which displays a welcome message to the user

import spaceworld


def hello(name: str):
    print(f"Hello {name}")


if __name__ == '__main__':
    spaceworld.run(hello)

Now let's run this script and see what happens.

$ python app.py hello

ERROR: Missing required argument: 'name'

We see an error due to the absence of the name argument. Let's welcome bino

$ python app.py hello bino

Hello bino

Async command

Creating an asynchronous command

import asyncio

import spaceworld


async def sleep(second: int):
    await asyncio.sleep(second)
    print(f"Hello in {second} second")


if __name__ == '__main__':
    spaceworld.run(sleep)

Copy that to a file main.py.

Test it:

$ python .\main.py sleep 1

# After 1 second
Hello in 1 second

$ python .\main.py sleep

# After 1 second
Hello in 1 second

$ python .\main.py sleep 5

# After 5 second
Hello in 5 second

The validation Command

Creating a validation Command

from typing import Annotated

import spaceworld


def check(
        age: Annotated[
            int,
            lambda x: x if x >= 18 else
            ValueError("The user must be over 18 years old")]):
    print(f"Hello {age} year old")


if __name__ == '__main__':
    spaceworld.run(check)

Copy that to a file main.py.

Test it:

$ python .\main.py check 1

ERROR:Invalid argument for 'age':
Error in the Annotated validation for `1`: Arg: 1, Error: The user must be over 18 years old, <class 'spaceworld.exceptions.annotations_error.AnnotationsError'>      

$ python .\main.py check 15

ERROR:Invalid argument for 'age': 
Error in the Annotated validation for `15`: Arg: 15, Error: The user must be over 18 years old, <class 'spaceworld.exceptions.annotations_error.AnnotationsError'>

$ python .\main.py check 18

Hello 18 year old

$ python .\main.py check -1

ERROR:Invalid argument for 'age': 
Error in the Annotated validation for `-1`: Arg: -1, Error: The user must be over 18 years old, <class 'spaceworld.exceptions.annotations_error.AnnotationsError'>

Great! As we can see, we entered the hello command with the bino argument and the script displayed greeting messages to him.

But what if we want to make a conclusion in big letters? Then let's add a flag.

License

This project is licensed under the terms of the MIT license.

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

spaceworld-0.1.2.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

spaceworld-0.1.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file spaceworld-0.1.2.tar.gz.

File metadata

  • Download URL: spaceworld-0.1.2.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for spaceworld-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9fe60a8354cbebd562e213c9938dc11a6bd1aa0b36e9ed6c6f85bfa242b4d0ea
MD5 d13a5409051aca7927b8965eaea9668c
BLAKE2b-256 426249e4c61a51cb5709465a083149387fb4264523ab0e293dcc78a2c6379edf

See more details on using hashes here.

File details

Details for the file spaceworld-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: spaceworld-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for spaceworld-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d22d909fb622c1bdf24557c814563a39b52999d115a5705cde3fd8475cc5164
MD5 cf0119ce982db85cf920a485299293b3
BLAKE2b-256 254aca565ac4be0a14837ef348204e65b7852531084cdc6ee820457ece9e5c58

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