sputchedtools


Namesputchedtools JSON
Version 0.31.1 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2025-01-25 19:32:23
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SputchedTools

Simple, lazy-import, powerful multi-purpose module, initially created to reduce repetitive functions definitions across projects

## Installation

```bash
pip install sputchedtools
```

## Features

# CLI

### Timer (1), NewLiner (2)
Use as context manager to (1) measure code execution time, with formatting and lap (semi) support, (2) print new line before and after code block

```python
with NewLiner(), Timer('Taken time: %s %ms %us'):
	...

async with Timer(False) as t: # Do not echo anything
	...
	lap1: float = t.lap("some action")

print(*t.laps, t.diff, sep = '\n')
```

### ProgressBar
Async-supported very simple executed task counter

```python
for i in ProgressBar(
	iterator = range(10), # Or Coroutine Iterator if using `async for`
	text = 'Processing...',
	# task_amount = ..., <- If iterator doesn't have __len__ attribute
	final_text = 'Done!\n',
):
	...
```

### Anim
Iterates through given/default chars at configurable delay while executing code block. Supports dynamic text editing without shitting terminal. Supports manual updating

```python
with Anim(
	prepend_text = 'Downloading ...', append_text = '',
	just_clear_char = False, # On exit
	clear_on_exit = True,
	delay = 0.1,
	manual_update = False, # Manual Anim.update()
	# chars = (..., ...)
) as a:

	# a.set_text()
	# a.set_chars()
	__import__('time').sleep(1)
```

### Config, Option
Define option list and let user modify them via terminal

```python
options = [
	Option(
		name = f'Set {i}',
		value: str = str(i),
		callback = Callbacks.direct # In-terminal edit
		# callback = Callbacks.toggle # Simple toggle
		# values = ('val1', 'val2') # Iterates through it on arrow/enter key
	)
	for i in range(9)
]

# Results received as OptionName: Value
results: dict[str] = Config(
	options = options,
	per_page = 9, # Let's you navigate through options with 1-9 keys
	callback_option_name = True # Wether to pass option name or its index to custom option callbacks
).win_cli()
```

# Utilities

## aio

### Methods:
 - aio.request()
	- aiohttp/httx/niquests wrapper
 - aio.get()
	- aio.request('GET') wrapper
 - aio.open()
	- aiofiles wrapper
 - aio.sem_task()
	- asyncio.Semaphore wrapper

```python
async def main():
	response = await aio.get(
		url = 'https://example.com',
		toreturn = ['text', 'status'], # Response attribute list
		# session = ...,
		raise_exceptions = False, # If True, replaces failed attributes with `None`, keeping `toreturn` length
		# Session provider
		httpx = False,
		niquests = False,
		# **request_args: headers, params, etc.
	)
	text = response[0] or 'None'

	await aio.open(
		file = 'response.txt',
		action = 'write',
		mode = 'w',
		content = text
	)
```

## num
### Methods:
 - num.shorten
	- 10_000_000 -> 10M

- num.unshorten
	- 10M -> 10_000_000.0

- num.decim_round
	- Safely rounds float's decimals

```python
file_size = num.shorten(
	value = 25_000_000,
	decimals = -1,
	suffixes = num.fileSize_suffixes # or num.sfx
) # 23.8 MB

num.decim_round(
	value = 0.000000004801,
	decimals = 4, # How many to leave
	round_if_num_gt_1 = True,
	precission = 20, # format(value, f'.{percission}')
	# decims = [...] if decimals argument is -1, this can be passed to change how many decimals to leave: default list is [1000, 100, 10, 5], List is iterated using enumerate(), so by each iter. decimal amount increases by 1 (starting from 0)
)
```

## Methods

#### enhance_loop() => installs uvloop or winloop
#### get_content() => Returns source byte content (raw, buffer, file)
#### write_content() => see docstring

## compress
Better explain here:

```python
compress(
	source = ..., # bytes, file/folder path, stream
	algorithm = 'lz4', # Supported are specified in `Algorithms` Literal
	output = ..., # False - bytes, file path, stream
	ignored_exceptions = (...) # Exceptions tuple to ignore when tar-ing directory. Default is (PermissionError, OSError),
	tar_in_memory = True,
	tar_if_file = False, # Directly compresses file content
	compression_level = None, # Use only if you know compression algorithm you use
	check_algorithm_support = False
)
```

## decompress
Gladly much simpler than `compress`, i'm tired writing this readme

```python
decompress(
	source = ..., # bytes, file path, stream
	algorithm = ..., # optional, function autodetects it, stops at `brotli` (undetectable) and raises if not it
	output = ... # False -> bytes, directory/file path, stream
)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sputchedtools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Sputchik <sputchik@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fa/d8/4bc4e8a840eaf182eb06ac607d4333655f189fd81de04f770fb775c6e9ec/sputchedtools-0.31.1.tar.gz",
    "platform": null,
    "description": "# SputchedTools\r\n\r\nSimple, lazy-import, powerful multi-purpose module, initially created to reduce repetitive functions definitions across projects\r\n\r\n## Installation\r\n\r\n```bash\r\npip install sputchedtools\r\n```\r\n\r\n## Features\r\n\r\n# CLI\r\n\r\n### Timer (1), NewLiner (2)\r\nUse as context manager to (1) measure code execution time, with formatting and lap (semi) support, (2) print new line before and after code block\r\n\r\n```python\r\nwith NewLiner(), Timer('Taken time: %s %ms %us'):\r\n\t...\r\n\r\nasync with Timer(False) as t: # Do not echo anything\r\n\t...\r\n\tlap1: float = t.lap(\"some action\")\r\n\r\nprint(*t.laps, t.diff, sep = '\\n')\r\n```\r\n\r\n### ProgressBar\r\nAsync-supported very simple executed task counter\r\n\r\n```python\r\nfor i in ProgressBar(\r\n\titerator = range(10), # Or Coroutine Iterator if using `async for`\r\n\ttext = 'Processing...',\r\n\t# task_amount = ..., <- If iterator doesn't have __len__ attribute\r\n\tfinal_text = 'Done!\\n',\r\n):\r\n\t...\r\n```\r\n\r\n### Anim\r\nIterates through given/default chars at configurable delay while executing code block. Supports dynamic text editing without shitting terminal. Supports manual updating\r\n\r\n```python\r\nwith Anim(\r\n\tprepend_text = 'Downloading ...', append_text = '',\r\n\tjust_clear_char = False, # On exit\r\n\tclear_on_exit = True,\r\n\tdelay = 0.1,\r\n\tmanual_update = False, # Manual Anim.update()\r\n\t# chars = (..., ...)\r\n) as a:\r\n\r\n\t# a.set_text()\r\n\t# a.set_chars()\r\n\t__import__('time').sleep(1)\r\n```\r\n\r\n### Config, Option\r\nDefine option list and let user modify them via terminal\r\n\r\n```python\r\noptions = [\r\n\tOption(\r\n\t\tname = f'Set {i}',\r\n\t\tvalue: str = str(i),\r\n\t\tcallback = Callbacks.direct # In-terminal edit\r\n\t\t# callback = Callbacks.toggle # Simple toggle\r\n\t\t# values = ('val1', 'val2') # Iterates through it on arrow/enter key\r\n\t)\r\n\tfor i in range(9)\r\n]\r\n\r\n# Results received as OptionName: Value\r\nresults: dict[str] = Config(\r\n\toptions = options,\r\n\tper_page = 9, # Let's you navigate through options with 1-9 keys\r\n\tcallback_option_name = True # Wether to pass option name or its index to custom option callbacks\r\n).win_cli()\r\n```\r\n\r\n# Utilities\r\n\r\n## aio\r\n\r\n### Methods:\r\n - aio.request()\r\n\t- aiohttp/httx/niquests wrapper\r\n - aio.get()\r\n\t- aio.request('GET') wrapper\r\n - aio.open()\r\n\t- aiofiles wrapper\r\n - aio.sem_task()\r\n\t- asyncio.Semaphore wrapper\r\n\r\n```python\r\nasync def main():\r\n\tresponse = await aio.get(\r\n\t\turl = 'https://example.com',\r\n\t\ttoreturn = ['text', 'status'], # Response attribute list\r\n\t\t# session = ...,\r\n\t\traise_exceptions = False, # If True, replaces failed attributes with `None`, keeping `toreturn` length\r\n\t\t# Session provider\r\n\t\thttpx = False,\r\n\t\tniquests = False,\r\n\t\t# **request_args: headers, params, etc.\r\n\t)\r\n\ttext = response[0] or 'None'\r\n\r\n\tawait aio.open(\r\n\t\tfile = 'response.txt',\r\n\t\taction = 'write',\r\n\t\tmode = 'w',\r\n\t\tcontent = text\r\n\t)\r\n```\r\n\r\n## num\r\n### Methods:\r\n - num.shorten\r\n\t- 10_000_000 -> 10M\r\n\r\n- num.unshorten\r\n\t- 10M -> 10_000_000.0\r\n\r\n- num.decim_round\r\n\t- Safely rounds float's decimals\r\n\r\n```python\r\nfile_size = num.shorten(\r\n\tvalue = 25_000_000,\r\n\tdecimals = -1,\r\n\tsuffixes = num.fileSize_suffixes # or num.sfx\r\n) # 23.8 MB\r\n\r\nnum.decim_round(\r\n\tvalue = 0.000000004801,\r\n\tdecimals = 4, # How many to leave\r\n\tround_if_num_gt_1 = True,\r\n\tprecission = 20, # format(value, f'.{percission}')\r\n\t# decims = [...] if decimals argument is -1, this can be passed to change how many decimals to leave: default list is [1000, 100, 10, 5], List is iterated using enumerate(), so by each iter. decimal amount increases by 1 (starting from 0)\r\n)\r\n```\r\n\r\n## Methods\r\n\r\n#### enhance_loop() => installs uvloop or winloop\r\n#### get_content() => Returns source byte content (raw, buffer, file)\r\n#### write_content() => see docstring\r\n\r\n## compress\r\nBetter explain here:\r\n\r\n```python\r\ncompress(\r\n\tsource = ..., # bytes, file/folder path, stream\r\n\talgorithm = 'lz4', # Supported are specified in `Algorithms` Literal\r\n\toutput = ..., # False - bytes, file path, stream\r\n\tignored_exceptions = (...) # Exceptions tuple to ignore when tar-ing directory. Default is (PermissionError, OSError),\r\n\ttar_in_memory = True,\r\n\ttar_if_file = False, # Directly compresses file content\r\n\tcompression_level = None, # Use only if you know compression algorithm you use\r\n\tcheck_algorithm_support = False\r\n)\r\n```\r\n\r\n## decompress\r\nGladly much simpler than `compress`, i'm tired writing this readme\r\n\r\n```python\r\ndecompress(\r\n\tsource = ..., # bytes, file path, stream\r\n\talgorithm = ..., # optional, function autodetects it, stops at `brotli` (undetectable) and raises if not it\r\n\toutput = ... # False -> bytes, directory/file path, stream\r\n)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": null,
    "version": "0.31.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7a4dfb2ea5c2d23f4beed6b6134fef86df472a7b18ece83a084bd5574ea97f8",
                "md5": "67d901003512235993b15a75bdc7a2f1",
                "sha256": "d2f5a680daea1016bd093d1e833bf8318fd6c20088ace1a177519615b0fc3f8c"
            },
            "downloads": -1,
            "filename": "sputchedtools-0.31.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "67d901003512235993b15a75bdc7a2f1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 14592,
            "upload_time": "2025-01-25T19:32:22",
            "upload_time_iso_8601": "2025-01-25T19:32:22.101208Z",
            "url": "https://files.pythonhosted.org/packages/b7/a4/dfb2ea5c2d23f4beed6b6134fef86df472a7b18ece83a084bd5574ea97f8/sputchedtools-0.31.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fad84bc4e8a840eaf182eb06ac607d4333655f189fd81de04f770fb775c6e9ec",
                "md5": "1fc784dd980863f5412d372d641bc298",
                "sha256": "de0da9d558a85b71a1f63b2f421e6d9485b7e5f679cf3b96566eb641eb585a6d"
            },
            "downloads": -1,
            "filename": "sputchedtools-0.31.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1fc784dd980863f5412d372d641bc298",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 15748,
            "upload_time": "2025-01-25T19:32:23",
            "upload_time_iso_8601": "2025-01-25T19:32:23.993722Z",
            "url": "https://files.pythonhosted.org/packages/fa/d8/4bc4e8a840eaf182eb06ac607d4333655f189fd81de04f770fb775c6e9ec/sputchedtools-0.31.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-25 19:32:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sputchedtools"
}
        
Elapsed time: 0.39741s