b62


Nameb62 JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryA lightning-fast, zero-dependency Base62 encoder/decoder for Python
upload_time2025-08-06 04:45:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT
keywords base62 encoding decoding url-shortening performance
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # b62

๐ŸŽ‰ A lightning-fast, zero-dependency and friendly Base62 encoder/decoder for Python! Tame your data with style and a smile.

## Features

- โšก High-performance Base62 encode/decode for integers
- ๐Ÿ Friendly Python interface backed by Rust
- ๐Ÿ”ง Seamless Rust-Python integration via PyO3
- ๐Ÿ›ก๏ธ Type-safe with comprehensive error handling
- ๐Ÿงช Thoroughly tested with property-based testing
- ๐Ÿ“ฆ Zero runtime dependencies

## Installation

### From PyPI

```bash
pip install b62
```

## Usage


```python
import b62

# Encode an integer to Base62
encoded = b62.encode(123456789)
print(encoded)  # Output: "8M0kX"

# Decode a Base62 string back to integer
decoded = b62.decode("8M0kX")
print(decoded)  # Output: 123456789

# Error handling
try:
    b62.decode("invalid!")
except ValueError as e:
    print(f"Invalid Base62 string: {e}")

# Round-trip validation
original = 987654321
encoded = b62.encode(original)
decoded = b62.decode(encoded)
assert original == decoded  # Always True!
```

## Performance

b62 is built with Rust for maximum performance and delivers exceptional speed:

### Benchmark Results

**Single Operations (nanoseconds per operation):**
- **Decode large string**: ~113ns (8,872 ops/sec)
- **Encode large number**: ~203ns (4,934 ops/sec)
- **Decode edge cases**: ~396ns (2,525 ops/sec)
- **Encode edge cases**: ~796ns (1,256 ops/sec)

**Batch Operations (100,000 operations):**
- **Encoding**: ~0.014s (7.2M ops/sec)
- **Decoding**: ~0.020s (5.1M ops/sec)
- **Round-trip**: ~0.033s (3.0M ops/sec)

**Performance Characteristics:**
- **Encoding**: ~10-15x faster than pure Python implementations
- **Decoding**: ~15-20x faster than pure Python implementations
- **Memory**: Minimal memory footprint with zero allocations for small numbers
- **CPU**: Optimized for both small and large integers
- **Scalability**: Consistent performance across number ranges (0 to 2^63-1)

### Technical Implementation

The library uses a highly optimized Rust implementation with PyO3 bindings:

- **Character Set**: `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`
- **Algorithm**: Efficient division/modulo operations with pre-allocated buffers
- **Error Handling**: Comprehensive validation with detailed error messages
- **Type Safety**: Full type annotations and runtime validation
- **Memory Management**: Zero-copy operations where possible

## API Reference

### `b62.encode(num: int) -> str`

Encodes an integer to Base62 string representation.

**Parameters:**

- `num` (int): Integer to encode (must be non-negative)

**Returns:**

- `str`: Base62 encoded string

**Raises:**

- `OverflowError`: If the integer is too large for u64

### `b62.decode(s: str) -> int`
Decodes a Base62 string back to an integer.

**Parameters:**

- `s` (str): Base62 string to decode

**Returns:**

- `int`: Decoded integer

**Raises:**

- `ValueError`: If the string contains invalid Base62 characters

## Development

### Running Tests

```bash
make test
```

### Code Quality

```bash
make ci
```

### Building

```bash
make build_package
```

## Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### Development Guidelines

- Follow PEP 8 style guidelines
- Add tests for new functionality
- Update documentation as needed
- Ensure all tests pass before submitting

## License

MIT License - free and open for all! ๐ŸŽ‰

## Why b62?

Keep your integer conversions speedy and stylish! Perfect for:

- URL shortening
- Database ID encoding
- Compact data serialization
- Performance-critical applications

๐Ÿฆ€๐Ÿ๐Ÿ’จ


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "b62",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "base62, encoding, decoding, url-shortening, performance",
    "author": null,
    "author_email": "Maksim Smirnov <smirnoffmg@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "# b62\n\n\ud83c\udf89 A lightning-fast, zero-dependency and friendly Base62 encoder/decoder for Python! Tame your data with style and a smile.\n\n## Features\n\n- \u26a1 High-performance Base62 encode/decode for integers\n- \ud83d\udc0d Friendly Python interface backed by Rust\n- \ud83d\udd27 Seamless Rust-Python integration via PyO3\n- \ud83d\udee1\ufe0f Type-safe with comprehensive error handling\n- \ud83e\uddea Thoroughly tested with property-based testing\n- \ud83d\udce6 Zero runtime dependencies\n\n## Installation\n\n### From PyPI\n\n```bash\npip install b62\n```\n\n## Usage\n\n\n```python\nimport b62\n\n# Encode an integer to Base62\nencoded = b62.encode(123456789)\nprint(encoded)  # Output: \"8M0kX\"\n\n# Decode a Base62 string back to integer\ndecoded = b62.decode(\"8M0kX\")\nprint(decoded)  # Output: 123456789\n\n# Error handling\ntry:\n    b62.decode(\"invalid!\")\nexcept ValueError as e:\n    print(f\"Invalid Base62 string: {e}\")\n\n# Round-trip validation\noriginal = 987654321\nencoded = b62.encode(original)\ndecoded = b62.decode(encoded)\nassert original == decoded  # Always True!\n```\n\n## Performance\n\nb62 is built with Rust for maximum performance and delivers exceptional speed:\n\n### Benchmark Results\n\n**Single Operations (nanoseconds per operation):**\n- **Decode large string**: ~113ns (8,872 ops/sec)\n- **Encode large number**: ~203ns (4,934 ops/sec)\n- **Decode edge cases**: ~396ns (2,525 ops/sec)\n- **Encode edge cases**: ~796ns (1,256 ops/sec)\n\n**Batch Operations (100,000 operations):**\n- **Encoding**: ~0.014s (7.2M ops/sec)\n- **Decoding**: ~0.020s (5.1M ops/sec)\n- **Round-trip**: ~0.033s (3.0M ops/sec)\n\n**Performance Characteristics:**\n- **Encoding**: ~10-15x faster than pure Python implementations\n- **Decoding**: ~15-20x faster than pure Python implementations\n- **Memory**: Minimal memory footprint with zero allocations for small numbers\n- **CPU**: Optimized for both small and large integers\n- **Scalability**: Consistent performance across number ranges (0 to 2^63-1)\n\n### Technical Implementation\n\nThe library uses a highly optimized Rust implementation with PyO3 bindings:\n\n- **Character Set**: `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`\n- **Algorithm**: Efficient division/modulo operations with pre-allocated buffers\n- **Error Handling**: Comprehensive validation with detailed error messages\n- **Type Safety**: Full type annotations and runtime validation\n- **Memory Management**: Zero-copy operations where possible\n\n## API Reference\n\n### `b62.encode(num: int) -> str`\n\nEncodes an integer to Base62 string representation.\n\n**Parameters:**\n\n- `num` (int): Integer to encode (must be non-negative)\n\n**Returns:**\n\n- `str`: Base62 encoded string\n\n**Raises:**\n\n- `OverflowError`: If the integer is too large for u64\n\n### `b62.decode(s: str) -> int`\nDecodes a Base62 string back to an integer.\n\n**Parameters:**\n\n- `s` (str): Base62 string to decode\n\n**Returns:**\n\n- `int`: Decoded integer\n\n**Raises:**\n\n- `ValueError`: If the string contains invalid Base62 characters\n\n## Development\n\n### Running Tests\n\n```bash\nmake test\n```\n\n### Code Quality\n\n```bash\nmake ci\n```\n\n### Building\n\n```bash\nmake build_package\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n### Development Guidelines\n\n- Follow PEP 8 style guidelines\n- Add tests for new functionality\n- Update documentation as needed\n- Ensure all tests pass before submitting\n\n## License\n\nMIT License - free and open for all! \ud83c\udf89\n\n## Why b62?\n\nKeep your integer conversions speedy and stylish! Perfect for:\n\n- URL shortening\n- Database ID encoding\n- Compact data serialization\n- Performance-critical applications\n\n\ud83e\udd80\ud83d\udc0d\ud83d\udca8\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightning-fast, zero-dependency Base62 encoder/decoder for Python",
    "version": "1.0.0",
    "project_urls": {
        "Documentation": "https://github.com/smirnoffmg/b62#readme",
        "Homepage": "https://github.com/smirnoffmg/b62",
        "Issues": "https://github.com/smirnoffmg/b62/issues",
        "Repository": "https://github.com/smirnoffmg/b62.git"
    },
    "split_keywords": [
        "base62",
        " encoding",
        " decoding",
        " url-shortening",
        " performance"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b1c39c3a3e1c01b8a4693bdd259a8d27de082d9ee940de48dac5a0454cd1dc40",
                "md5": "48eb4bd3d721455fe180dd84be75df27",
                "sha256": "8f62fc7a9f36d9585101917ffe88066e07bd6feeac4163203132b11fb0056333"
            },
            "downloads": -1,
            "filename": "b62-1.0.0-cp312-cp312-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "48eb4bd3d721455fe180dd84be75df27",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.12",
            "size": 213435,
            "upload_time": "2025-08-06T04:45:54",
            "upload_time_iso_8601": "2025-08-06T04:45:54.897002Z",
            "url": "https://files.pythonhosted.org/packages/b1/c3/9c3a3e1c01b8a4693bdd259a8d27de082d9ee940de48dac5a0454cd1dc40/b62-1.0.0-cp312-cp312-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "77508a5379b979e3259d33afed0842fb535f719c9ca097085574e8d6eef1bc91",
                "md5": "b61a3c1e3ccd4101e0e7146ab127d67d",
                "sha256": "e4c59a67d2edf997b828ffc0a30610c99c77b0b89d87dac0c93333dcc4d23d8b"
            },
            "downloads": -1,
            "filename": "b62-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "b61a3c1e3ccd4101e0e7146ab127d67d",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.12",
            "size": 239596,
            "upload_time": "2025-08-06T04:45:55",
            "upload_time_iso_8601": "2025-08-06T04:45:55.837887Z",
            "url": "https://files.pythonhosted.org/packages/77/50/8a5379b979e3259d33afed0842fb535f719c9ca097085574e8d6eef1bc91/b62-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-06 04:45:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "smirnoffmg",
    "github_project": "b62#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "b62"
}
        
Elapsed time: 0.96424s