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 PyPI 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://github.com/Binobinos/SpaceWorld/docs/README.md

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

from spaceworld import run


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

Copy that to a file main.py.

Test it:

$ python main.py

Hello World

$ python main.py --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

from spaceworld import run


@run
def main(name: str):
    print(f"Hello {name}")

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

$ python spaceworld_.py 

ERROR: Missing required argument: 'name'

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

$ python spaceworld_.py bino

Hello bino

Async command

Creating an asynchronous command

import asyncio

from spaceworld import run


@run
async def main(second: int = 1):
    await asyncio.sleep(second)
    print(f"Hello in {second} second")

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

from spaceworld import run


@run
def main(
        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")

Copy that to a file main.py.

Test it:

$ python .\main.py 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'>

🆕 What's new in SpaceWorld 3.0?

  • Improved framework structure

  • Added support for TypedDict, byte, complex, bytearray, Unpack in *args, **kwargs

  • Fixed errors with confirm and others

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-3.0.0.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

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

spaceworld-3.0.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for spaceworld-3.0.0.tar.gz
Algorithm Hash digest
SHA256 4a6cd2bf33ef3b4c2b15d6654f3088caef4e2f0d6986a5a238cc8cf45e626c92
MD5 34763fc07463af5b95125fe788a5f415
BLAKE2b-256 0ed1d8fac9a307ecf008c6b731563d702b2471278f9a611994985d9f9c6fb687

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for spaceworld-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d552e518a469cb2eda71dece2bd7cc0b1aa5b9491de2de0353b2e97ebc922030
MD5 455fa9a220e78a14bb11a9610f8dcb2f
BLAKE2b-256 9b21333254a94423e0ac60689d4171b18e7a61c6f29dfcc3a0af58d350e5ad61

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