A high-performance Python SDK with Cython-optimized utilities for string manipulation, cryptography, object handling, and more.
Project description
pysha-sdk
A high-performance Python SDK with Cython-optimized utilities for string manipulation, cryptography, object handling, and more.
Features
- ๐ High Performance: Cython-optimized implementations for performance-critical operations
- ๐ฆ Comprehensive Utilities: String manipulation, cryptography, object handling, and more
- ๐ Automatic Fallback: Pure Python implementations when Cython extensions aren't available
- โ Well Tested: 84% code coverage with 179+ unit tests
- ๐ Type Safe: Full type hints and mypy support
- ๐ Well Documented: Comprehensive docstrings and examples
Installation
# Using pip
pip install pysha-sdk
# Using uv (recommended)
uv pip install pysha-sdk
# With optional dependencies
pip install pysha-sdk[inflect,phonenumbers,email,bson]
Quick Start
String Utilities
from pysha_sdk import (
to_camel_case,
to_snake_case,
extract_digits,
is_valid_email,
normalize,
slugify,
)
# Case conversion
to_camel_case("hello_world") # "helloWorld"
to_snake_case("HelloWorld") # "hello_world"
# String manipulation
extract_digits("abc123def") # "123"
is_valid_email("user@example.com") # (True, None)
# Text normalization
normalize("<p>Hello **world**!</p>") # "Hello world!"
# URL-friendly slugs
slugify("Hello World!") # "hello-world"
Crypto Utilities
from pysha_sdk import (
hash_password,
match_password,
uuidv7,
calculate_md5_hash,
generate_random_token,
)
# Password hashing
hashed = hash_password("my_password")
match_password("my_password", hashed) # True
# UUID generation
uuid = uuidv7() # UUIDv7 with timestamp
# Hashing
md5_hash = calculate_md5_hash("content") # "5d41402abc4b2a76b9719d911017c592"
# Random tokens
token = generate_random_token(32, "hex") # 32-character hex token
Object Utilities
from pysha_sdk import (
recursive_sort_keys,
ChangeKeysCase,
model_dump,
)
from pydantic import BaseModel
# Recursive key sorting
data = {"z": 1, "a": {"c": 2, "b": 1}}
sorted_data = recursive_sort_keys(data)
# {"a": {"b": 1, "c": 2}, "z": 1}
# Case conversion for dictionaries
ChangeKeysCase.to_camel_case({"first_name": "John"})
# {"firstName": "John"}
# Pydantic model dumping
class User(BaseModel):
name: str
age: int
user = User(name="John", age=30)
model_dump(user) # {"name": "John", "age": 30}
DictMixin
from pysha_sdk.utils.mixins.dict_mixin import DictMixin
class MyModel(DictMixin):
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
obj = MyModel(name="John", age=30)
# Dict-like access
obj["name"] # "John"
obj["nested.deep.value"] # Path-based access with glom
# Dict methods
list(obj.keys()) # ["name", "age"]
obj.get("missing", "default") # "default"
Modules
String Utilities (pysha_sdk.utils.strings)
Comprehensive string manipulation functions:
- Case Conversion:
to_camel_case,to_snake_case,to_kebab_case,to_pascale_case,to_constant_case,to_title_case - Encoding/Decoding:
to_hex,from_hex,to_base64,from_base64,to_ascii - Validation:
is_valid_email,is_valid_phone_number,is_valid_israeli_id,is_cron_expression,is_hex,is_ascii,is_hebrew - Text Processing:
normalize,slugify,deburr,words,compounder,extract_digits - URL Utilities:
to_url,flatten_url_params,delimited_path_join - Pluralization:
to_plural,to_singular(requiresinflect)
Crypto Utilities (pysha_sdk.utils.crypto)
Cryptographic and security functions:
- Password Management:
hash_password,encrypt_password,match_password - Hashing:
calculate_md5_hash - UUID Generation:
uuidv7,to_stable_uuid,uuidv7_to_datetime - Random Generation:
generate_random_id,generate_random_token,generate_unique_secure_token
Object Utilities (pysha_sdk.utils.objects)
Object and data structure manipulation:
- Pydantic Integration:
model_dump,dict_or_pydantic_model_to_dict - Key Operations:
recursive_sort_keys,ChangeKeysCase(camel, snake, kebab, Pascal, constant, dot case) - Type Utilities:
is_iterable_except_str_like,find_subclasses
DictMixin (pysha_sdk.utils.mixins.dict_mixin)
A mixin class that provides dict-like interface to objects:
- Dict-like access with
obj[key] - Path-based access with glom:
obj["nested.deep.value"] - All standard dict methods:
keys(),values(),items(),get(), etc. - Works seamlessly with Pydantic models
Performance
This package uses Cython to optimize performance-critical operations. When Cython extensions are available, functions automatically use optimized implementations. If Cython isn't available, the package falls back to pure Python implementations.
Optimized Functions:
- String operations:
extract_digits,is_ascii,is_hex,is_hebrew,to_hex,from_hex,to_base64,from_base64,to_ascii - Crypto operations:
calculate_md5_hash,encrypt_password,match_password,to_stable_uuid,uuidv7,uuidv7_to_datetime - Object operations:
recursive_sort_keys,change_keys_case,is_iterable_except_str_like - DictMixin operations: All dict-like operations
Requirements
- Python 3.13+
- Optional dependencies:
inflect- For pluralization featuresphonenumbers- For phone number validation/formattingemail-validator- For email validationpymongo- For ObjectId conversion (bson)
Development
Setup
# Clone the repository
git clone https://github.com/guysha94/pysha-sdk.git
cd pysha-sdk
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync --dev
# Build the package
uv build
Running Tests
# Run all tests
uv run pytest tests/ -v
# Run with coverage
uv run pytest tests/ -v --cov=src/pysha_sdk --cov-report=html
# Run specific test file
uv run pytest tests/test_strings.py -v
Code Quality
# Linting
uv run ruff check src/ tests/
# Formatting
uv run ruff format src/ tests/
# Type checking
uv run mypy src/pysha_sdk
Building
# Build wheel and sdist
uv build
# Install locally
uv pip install dist/pysha_sdk-*.whl
Project Structure
pysha-sdk/
โโโ src/
โ โโโ pysha_sdk/
โ โโโ __init__.py # Main package exports
โ โโโ utils/
โ โโโ strings/ # String utilities
โ โ โโโ __init__.py
โ โ โโโ _native.pyx # Cython optimizations
โ โ โโโ _py.py # Python fallback
โ โ โโโ regex.py # Regex patterns
โ โโโ crypto/ # Crypto utilities
โ โ โโโ __init__.py
โ โ โโโ _native.pyx # Cython optimizations
โ โ โโโ _py.py # Python fallback
โ โโโ objects/ # Object utilities
โ โ โโโ __init__.py
โ โ โโโ _native.pyx # Cython optimizations
โ โ โโโ _py.py # Python fallback
โ โโโ mixins/
โ โโโ dict_mixin/ # DictMixin class
โ โโโ __init__.py
โ โโโ _native.pyx
โ โโโ _py.py
โโโ tests/ # Test suite
โ โโโ test_strings.py
โ โโโ test_crypto.py
โ โโโ test_objects.py
โ โโโ test_dict_mixin.py
โ โโโ test_strings_py_fallback.py
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # CI/CD pipeline
โโโ pyproject.toml # Project configuration
โโโ setup.py # Cython build setup
โโโ README.md # This file
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Guidelines
- Follow the existing code style (enforced by ruff)
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass and coverage is maintained
- Type hints are required for all functions
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
guysha94
- Email: guy.sha@superplay.co
Acknowledgments
- Built with Cython for performance
- Uses uv for fast package management
- Inspired by lodash and similar utility libraries
Changelog
0.1.0 (2024)
- Initial release
- String utilities with Cython optimizations
- Crypto utilities (password hashing, UUID generation)
- Object utilities (key sorting, case conversion)
- DictMixin for dict-like object access
- Comprehensive test suite (84% coverage)
- CI/CD pipeline with automated testing and publishing
Support
For issues, questions, or contributions, please open an issue on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pysha_sdk-0.1.0.tar.gz.
File metadata
- Download URL: pysha_sdk-0.1.0.tar.gz
- Upload date:
- Size: 39.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c9673c4906c54eaad61d9197099434584b8c9a4b4ac3d680c7529b6d5bb2f18
|
|
| MD5 |
044b4a95449abd52cac99cfd00f87872
|
|
| BLAKE2b-256 |
a663f50128ea8c64103fbcd6baaf97842c127365b516cd5c2c9890943a975611
|
Provenance
The following attestation bundles were made for pysha_sdk-0.1.0.tar.gz:
Publisher:
ci.yml on shakedguy/pysha-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysha_sdk-0.1.0.tar.gz -
Subject digest:
7c9673c4906c54eaad61d9197099434584b8c9a4b4ac3d680c7529b6d5bb2f18 - Sigstore transparency entry: 788309090
- Sigstore integration time:
-
Permalink:
shakedguy/pysha-sdk@818716670ade1b25d86d6b68737c1834e302be1d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/shakedguy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@818716670ade1b25d86d6b68737c1834e302be1d -
Trigger Event:
release
-
Statement type: