Spaceworld is a new generation Cli framework for convenient development of your teams written in Python 3.12+ with support for asynchronous commands
Reason this release was yanked:
Не нужная версия
Project description
SpaceWorld
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 spaceworld_.py hello
ERROR: Missing required argument: 'name'
We see an error due to the absence of the name argument. Let's welcome bino
$ python spaceworld_.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'>
New features in v1.0.0
The decorators' style
Modules as a command
Checking the number of positional and named arguments
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
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 spaceworld-0.0.0.tar.gz.
File metadata
- Download URL: spaceworld-0.0.0.tar.gz
- Upload date:
- Size: 29.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20bfbec3938dea20969ae9e57d41c6e62293af97ee300fea6eadc835b4d2829f
|
|
| MD5 |
d15e537ae13798c19ff0a694e2a4052a
|
|
| BLAKE2b-256 |
9eb6a2ab3beaebe50189a29d102b34116b4ef4b520d7e1825aad4ec08d9a672c
|
File details
Details for the file spaceworld-0.0.0-py3-none-any.whl.
File metadata
- Download URL: spaceworld-0.0.0-py3-none-any.whl
- Upload date:
- Size: 30.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ccec911bc5c7df592776d8762a03c0d96796d1eabd6ddc4d84aab70d1ace2e0
|
|
| MD5 |
6ca875bea464ddb77dae58fe09ab9293
|
|
| BLAKE2b-256 |
398ec8521cfa06dfa7da6408658fe4e4ef908f8d0955eb51944aeee998d95a9f
|