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

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

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.1.tar.gz (20.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.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for spaceworld-0.1.1.tar.gz
Algorithm Hash digest
SHA256 359240d5e98724d2175fd57f237ce96df07470c77c0765ee37d4e8325b72d999
MD5 24c8933601c43974dcac2eaed313001c
BLAKE2b-256 768285c0ad98326c4312da18085e667393075162babce41e40bc8c03c8b3cd1a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for spaceworld-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 606d8aa1472916822de3c9d7f939cd9f213ddf9ae29ed4056c2ae445af68b6c4
MD5 918ae33cf1aef1380c71c84002c88b77
BLAKE2b-256 9ef18c36900ea32d44203233bc7192dd6cd8a1d4511e13ac06ea1aa3ae51e15f

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