python_base_flex
A flexible Python implementation for encoding and decoding data using various base-N encodings (e.g., Base64, Base32, Base16, Base4096, etc.). The implementation supports custom alphabets and optional separators between encoded characters.
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.3%) to scientific vocabulary
Repository
A flexible Python implementation for encoding and decoding data using various base-N encodings (e.g., Base64, Base32, Base16, Base4096, etc.). The implementation supports custom alphabets and optional separators between encoded characters.
Basic Info
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 1
Metadata Files
README.md
Base-Flex Encoder/Decoder
A flexible Python implementation for encoding and decoding data using various base-N encodings (e.g., Base64, Base32, Base16, Base4096, etc.). The implementation supports custom alphabets and optional separators between encoded characters.
Note: If you are looking for a faster, more robust implementation for standart encodings, use the standard library. This library goal is to provide a flexible implementation for custom base-N encodings and alphabets!
Features
- Support for any base-N encoding with power-of-2 alphabet size
- Built-in support for common encodings (Base64, Base32)
- Pre-defined standard alphabets in
alphabetsmodule - Configurable padding character
- Optional separators between encoded characters
- Comprehensive test suite
- Type hints and detailed documentation
- Efficient implementation using bitwise operations
Installation
bash
pip install base-flex
Usage
```python from baseflex import BaseN from baseflex.alphabets import BASE64ALPHABET, BASE32ALPHABET
Base64 encoding/decoding
base64 = BaseN(list(BASE64_ALPHABET))
Basic encoding/decoding
encoded = base64.encode(b"Hello, World!") decoded = base64.decode(encoded)
Using separators for better readability
base64sep = BaseN(list(BASE64ALPHABET), separator="-") encodedwithsep = base64sep.encode(b"Hello, World!") decodedwithsep = base64sep.decode(encodedwithsep)
Base32 encoding/decoding
base32 = BaseN(list(BASE32ALPHABET)) encodedbase32 = base32.encode(b"Hello, World!") decodedbase32 = base32.decode(encodedbase32)
Custom base-N encoding
You can create your own base-N encoding by providing a custom alphabet
The alphabet length (excluding padding char) must be a power of 2
The last character of the alphabet is the padding character, and every element must be unique!
customalphabet = list("01234567=") # Base8 example base8 = BaseN(customalphabet) encodedbase8 = base8.encode(b"Hello") decodedbase8 = base8.decode(encoded_base8) ```
Project Structure
base_flex/
├── base_flex/
│ ├── __init__.py
│ ├── base_flex.py # Main implementation
│ ├── alphabets.py # Pre-defined standard alphabets
│ └── tests/
│ ├── __init__.py
│ └── test_base_flex.py
├── README.md
└── pyproject.toml
Running Tests
The project includes a comprehensive test suite. To run the tests:
bash
python -m unittest discover -v && coverage report
Implementation Details
The implementation follows these steps:
Encoding
- Converts input bytes to a binary string
- Splits the binary string into n-bit chunks
- Converts each chunk to a base-N character
- Adds padding if necessary
- Joins characters with separator (if specified)
Decoding
- Removes separators and padding
- Converts each character back to its binary representation
- Concatenates binary strings
- Converts binary string back to bytes
Validation
- Ensures alphabet length (excluding padding) is a power of 2
- Checks for duplicate characters in the alphabet
- Validates input characters during decoding
License
Citation
If you use this software, please cite it as below:
APA
Mattfeld, V. (2025). Base-Flex (Version 0.1.0) [Computer software]. https://github.com/valerius21/base-flex
BibTeX
bibtex
@software{Mattfeld_Base-Flex_2025,
author = {Mattfeld, Valerius},
month = feb,
title = {{Base-Flex}},
url = {https://github.com/valerius21/base-flex},
version = {0.1.0},
year = {2025}
}
Owner
- Name: Valerius Mattfeld
- Login: valerius21
- Kind: user
- Location: Göttingen, Germany
- Company: @elegal-ev @ksb-intax
- Website: https://valerius.me
- Twitter: valerius_mat
- Repositories: 110
- Profile: https://github.com/valerius21
full-stack developer / computer science and law graduate
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Mattfeld"
given-names: "Valerius"
orcid: "https://orcid.org/0000-0003-0263-0332"
title: "Base-Flex"
version: 0.1.0
date-released: 2025-02-01
url: "https://github.com/valerius21/base-flex"
GitHub Events
Total
- Release event: 1
- Push event: 3
- Create event: 3
Last Year
- Release event: 1
- Push event: 3
- Create event: 3
Dependencies
- coverage 7.6.10
- coverage ^7.6.10
- python ^3.9