Skip to main content

suger

version = 0.2.2

Introduce 介绍

suger is a sugar ~

Feature:

  1. python @decorator = Java @annotation / C# [Required(ErrorMessage = "{0} is required")]
  2. python Stream = Java Stream / C# LinQ

How to use 如何使用

install 安装依赖

pip install suger

Stream 流式计算 / from v0.2.0

from suger.stream.Stream import Stream

    def test_demo(self):
        data = [1, 2, 3, 3, 4, 5]
        result = Stream(data)\
            .filter(lambda x: x % 2 == 0) \
            .sort(reverse=True) \
            .map(lambda x: x * 2) \
            .toSet()
        self.assertEqual(result, {8, 4})

decorator 装饰器/注解

@string | str

@string
class MockData:
    def __init__(self, age):
        self.age = age


data = MockData(18)

# Output = "MockData(age=18)"
print(data)

@csv | CSV

@csv
class MockData:
    def __init__(self, name, age):
        self.name = name
        self.age = age
        self.emptyTips = ''




class Test(TestCase):
    def test_csv(self):
        data = MockData(name='neko', age=18)

        # csv 输出文本
        print(data.csv_str())
        # csv 的格式
        print(data.csv_format())

# 示例中,有个字段为空
# neko,18,
# name,age,emptyTips

工具

FileUtils 文件工具

from suger.common import FileUtils

# 递归扫描, png 格式
fileArray = FileUtils.scanDir('C:/Users/suger/Documents/WeChat Files', 'png')
print(fileArray)

ObjectUtils 对象工具

from suger.common import ObjectUtils

# true
ObjectUtils.isNull(None)

#  true
data = {}
ObjectUtils.isNotNull(data)

SSH

from unittest import TestCase

from suger.terminal import SSH


class TestSSH(TestCase):
    def test_connect(self):
        ssh = SSH(host='localhost', password='root')
        ssh.connect()
        output, err = ssh.execute_command('ls .')
        print(output)

Data Operator 数据操作

XML

from unittest import TestCase

from suger.data_operator import XmlUtils, ElementTree

class TestXmlUtils(TestCase):
    def test_find_element(self):

        # 读取 XML 文件
        xml = XmlUtils('example.xml')

        # 查询节点
        node = xml.find_element('.//book[@id="123"]')
        print(node.text)

        # 修改节点值
        xml.set_element_value('.//book[@id="123"]/name', 'New Book Title')

        # 添加节点
        new_element = ElementTree.Element('book', {'id': '456'})
        sub_element1 = ElementTree.SubElement(new_element, 'name')
        sub_element1.text = 'New Book'
        sub_element2 = ElementTree.SubElement(new_element, 'author')
        sub_element2.text = 'New Author'
        xml.add_element('.//books', new_element)

        # 删除节点
        xml.remove_element('.//book[@id="123"]')

        # 写入文件
        xml.write_file('new_example.xml')

Excel

from unittest import TestCase

from suger.data_operator.ExcelUtils import ExcelUtils


class TestExcelUtils(TestCase):

    def test_serialize(self):
        # 读取 Excel 文件
        workbook = ExcelUtils.load_workbook("example.xlsx")

        # 获取指定名称的 sheet 对象
        sheet = ExcelUtils.get_sheet_by_name(workbook, "Sheet1")

        # 将 sheet 序列化为一个列表
        data = ExcelUtils.serialize(sheet, skip_rows=1)

        # 对列表进行操作

        # 反序列化列表到指定的 sheet 对象
        ExcelUtils.deserialize(sheet, data, skip_rows=1)

        # 保存 Excel 文件
        ExcelUtils.save_workbook(workbook, "example.xlsx")

my project init

git init

 git remote add github https://github.com/SolarisNeko/neko233-python-suger.git
 git remote add origin https://gitee.com/SolarisNeko/neko233-python-suger.git

Metadata

Release files for suger 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for suger 0.2.2
File Size Uploaded Provenance Actions
suger-0.2.2.tar.gz 17.1 kB Without provenance Details for suger-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for suger 0.2.2
File Interpreter ABI Platform Actions
suger-0.2.2-py3-none-any.whl Python 3 none any Details for suger-0.2.2-py3-none-any.whl

Total release size: 35.6 kB

Release files / suger-0.2.2.tar.gz

Download URL suger-0.2.2.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ac19694cd21a12974d59f22c71967d2c662b0a87118c869f516ccf82fd58e30a
BLAKE2b-256 checksum
How to use checksums
2849df9316b4f5cd503ce77ec88e3178859a184270250af322c8c1d2152b3cc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / suger-0.2.2-py3-none-any.whl

Download URL suger-0.2.2-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6b5d4b12dcab723dafb1ada4af40306a53601c987d821ca595566aa3b5107bd
BLAKE2b-256 checksum
How to use checksums
d46672416c1c12faaecd7b7eb6e36e15398227a28e07912ef880b7691f27e6e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for suger 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page