Skip to main content

zhige office的个人工具箱

Project description

ZhigeTools

English | 简体中文

Introduction

ZhigeTools is an open-source Python toolkit that provides a collection of utility functions for daily work. It is designed to simplify common tasks by offering easy-to-use wrappers.

Installation

pip install zhigetools

Development

See Development Guide for information about contributing to this project.

Features

  • Character Conversion Tools

    base_to_number

    • Converts a string to a number, supporting custom bases and custom symbols for the base.
    from zhige_tools.base_converter import base_to_number
    

    number_to_base

    • Converts a number to a string, supporting custom bases and custom symbols for the base.
    from zhige_tools.base_converter import number_to_base
    
  • INI Configuration File Tools

    • Read, write and validate INI configuration files with type checking
    from zhige_tools.ini_reader import read_ini_file, write_ini_file, initialize_ini_file
    
    # Define configuration rules
    rules = {
        'Database': {
            'host': str,
            'port': int,
            'debug': bool
        }
    }
    
    # Initialize with default values
    initialize_ini_file('config.ini', rules, default_values)
    
    # Read configuration
    config = read_ini_file('config.ini')
    
  • Snowflake ID Generator

    • Distributed unique ID generator based on Twitter's Snowflake algorithm
    • Support multiple machine IDs and clock drift correction
    • Support decimal, hexadecimal and base62 output formats
    from zhige_tools.snowflake import snowflake_handler
    
    # Initialize with different bases (10/16/62)
    snowflake_handler.create_snowflake(machine_id=1)  # decimal (default)
    snowflake_handler.create_snowflake(machine_id=2, base=16)  # hexadecimal
    snowflake_handler.create_snowflake(machine_id=3, base=62)  # base62
    
    # Generate ID
    dec_id = snowflake_handler.get_id(1)    # e.g., "1234567890123456"
    hex_id = snowflake_handler.get_id(2)    # e.g., "1234abcd5678"
    b62_id = snowflake_handler.get_id(3)    # e.g., "Az9bXy8K"
    
    # Parse ID
    parsed = snowflake_handler.parse_id(dec_id, 1)
    print(parsed)  # {'original_id': '1234567890123456', 'decimal_id': 1234567890123456, 
                   #  'datetime': '2024-02-10 10:30:00', 'machine_id': 1, 'sequence': 0,
                   #  'base': 10, 'base_name': '十进制'}
    

Changelog

  • 2024.02.10 v0.2.0

    • Enhanced Snowflake ID generator
      • Added support for hexadecimal and base62 output formats
      • Added base configuration and validation
      • Improved ID parsing with detailed information
    • Improved INI configuration file tools
    • Updated documentation and examples
  • 2024.02.10 v0.1.3

    • Added Snowflake ID generator
    • Added INI configuration file tools
  • 2021.10.25 v0.1.1

    • Added function hints, updated README.md
  • 2021.10.25 v0.1.0

    • Initial release

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

zhige_tools-0.2.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

zhige_tools-0.2.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file zhige_tools-0.2.1.tar.gz.

File metadata

  • Download URL: zhige_tools-0.2.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.4rc1

File hashes

Hashes for zhige_tools-0.2.1.tar.gz
Algorithm Hash digest
SHA256 87799659d86650bdcd3f07f476993c3316c29e76afee72c1bec9ce06a06a4112
MD5 349233768c4b52c717ce960952980a4b
BLAKE2b-256 4a939c727678f22d0355630d8dbfdd4263e25ea849336460f239ca79328f9c0a

See more details on using hashes here.

File details

Details for the file zhige_tools-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: zhige_tools-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.4rc1

File hashes

Hashes for zhige_tools-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38a3935537ea8063439c98059681bb30c608af14ff61b59b0b03231934da6e09
MD5 6a187fc9fc6f9e4ea329aa80bcd7e1e0
BLAKE2b-256 330bcf1ad29c5be982f6ea46b5320dcbf2cd2486f6c1bed13c62f86775a3e500

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