Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ ec_tools.egg-info/

upload.sh
.*swp

38 changes: 16 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
repos:
# --- isort: import sorter ---
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--line-length", "120"]
# --- autoflake: remove unused imports/vars ---
- repo: https://github.com/myint/autoflake
rev: v2.3.1
args: ["--profile=black"]
name: isort (python)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: autoflake
args: [
"--in-place",
"--remove-unused-variables",
"--remove-all-unused-imports",
]
exclude: "__init__.py"
# --- Black: Python code formatter ---
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 24.8.0 # use a stable release
rev: 25.1.0
hooks:
- id: black
language_version: python3
args: ["--line-length=120"]
# --- YAML lint/format ---
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
args: [--line-length=120]
- repo: https://github.com/myint/autoflake
rev: v2.3.1
hooks:
- id: check-yaml

- id: autoflake
args: [ '--remove-all-unused-imports', '--in-place' ]
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[MESSAGES CONTROL]
disable=missing-docstring,broad-exception-caught,too-many-return-statements,too-many-arguments,too-many-positional-arguments

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,76 @@
# ec_tools

A lightweight Python toolbox for data modeling, SQLite DAOs, encrypted key-value storage, and small productivity utilities.

## Highlights
- Data objects with JSON serialization and type-aware formatting.
- SQLite client + DAO layer with query generation.
- KV DAO with optional AES-backed encryption.
- Encryption helpers for bytes, chunks, and files.
- Utility helpers for IO, hashing, logging, and timing.

## Requirements
- Python >= 3.12

## Install (from source)
```bash
pip install -e .
```

## Quick start
### Encrypted KV storage with a KeyManager
```python
from ec_tools.database import CipherKvDao, SqliteClient, SqliteKvDao
from ec_tools.tools.cipher import AesCipherGenerator
from ec_tools.tools.key_manager import KeyManager

sqlite_client = SqliteClient(":memory:")
kv_dao = SqliteKvDao(sqlite_client)
cipher_generator = AesCipherGenerator()
cipher_kv_dao = CipherKvDao(kv_dao, cipher_generator)

manager = KeyManager(cipher_kv_dao, "my-password")
manager.refresh_keys(["token", "cookie"])
print(manager.get_key("token"))
```

### Build headers from stored secrets
```python
from ec_tools.tools.headers_manager import HeadersManager

headers = HeadersManager(manager, ["token"], {"User-Agent": "ec-tools"}).get()
print(headers)
```

## Data objects
Define dataclasses that serialize to/from JSON with helpers for enums, lists, sets, and nested objects.
```python
import dataclasses
from ec_tools.data import DataObject

@dataclasses.dataclass
class User(DataObject):
name: str
age: int

user = User.from_json({"name": "Ada", "age": "42"})
print(user.to_json())
```

## Encryption helpers
- `AesCipher` for encrypting/decrypting bytes.
- Chunked and file-level encryption utilities in `ec_tools.tools.cipher`.

## Project layout
- `ec_tools/data`: data-object helpers and JSON formatting.
- `ec_tools/database`: SQLite client, DAO, and KV DAO.
- `ec_tools/tools`: key/headers managers, cipher tools, thread pool.
- `ec_tools/utils`: IO, hashing, logging, and timing helpers.

## Development
```bash
pytest
```

## License
MIT
7 changes: 7 additions & 0 deletions ec_tools/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
from .data_object import CustomizedJsonEncoder, DataObject, Formatter
from .json_type import JsonType

__all__ = [
"CustomizedJsonEncoder",
"DataObject",
"Formatter",
"JsonType",
]
13 changes: 13 additions & 0 deletions ec_tools/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,16 @@
from .sqlite_dao.sqlite_dao import SqliteDao
from .sqlite_dao.sqlite_data_object import SqliteDataObject
from .sqlite_dao.sqlite_query_generator import SqliteQueryGenerator

__all__ = [
"CipherKvDao",
"ONE_THOUSAND_YEAR",
"KvDao",
"KvData",
"SqliteKvDao",
"SqliteClient",
"SqliteQuery",
"SqliteDao",
"SqliteDataObject",
"SqliteQueryGenerator",
]
4 changes: 4 additions & 0 deletions ec_tools/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from .thread_pool import CustomThreadPoolExecutor

__all__ = [
"CustomThreadPoolExecutor",
]
10 changes: 10 additions & 0 deletions ec_tools/tools/cipher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
from .cipher import Cipher, SecrectKey
from .cipher_generator.aes_cipher_generator import AesCipherGenerator
from .cipher_generator.cipher_generator import CipherGenerator

__all__ = [
"AesCipher",
"AesConfig",
"AesMode",
"Cipher",
"SecrectKey",
"AesCipherGenerator",
"CipherGenerator",
]
5 changes: 4 additions & 1 deletion ec_tools/tools/cipher/file_encryption_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from ec_tools.tools.cipher.aes_config import AesMode
from ec_tools.tools.cipher.chunk_config import ChunkConfig
from ec_tools.tools.cipher.chunk_encryption_utils import decrypt_by_chunk, encrypt_by_chunk
from ec_tools.tools.cipher.chunk_encryption_utils import (
decrypt_by_chunk,
encrypt_by_chunk,
)
from ec_tools.utils.io_utils import chunk_read_file


Expand Down
44 changes: 44 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[build-system]
requires = [
"setuptools>=61.0",
"wheel"
]
build-backend = "setuptools.build_meta"

[project]
name = "ec_tools"
version = "0.3.0"
description = "A collection of tool for EC."
readme = "README.md"
requires-python = ">=3.12"
license = { text = "MIT" }
dependencies = [
"colorama==0.4.6",
"pycryptodome==3.20.0",
"setuptools==69.5.1",
]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
]

[project.optional-dependencies]
dev = ["black"]

[tool.black]
line-length = 120

[dependency-groups]
dev = [
"pre-commit>=4.5.1",
]

[tool.pytest.ini_options]
pythonpath = ["."]
testpaths = [
"tests/"
]

[tool.setuptools.packages.find]
where = ["ec_tools"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Discover packages from the project root

Setting where = ["ec_tools"] makes setuptools search inside the ec_tools/ directory as the package root, so the built distribution will not include the top-level ec_tools package (it resolves subpackages like data, database, etc. as top-level names instead). In an installed wheel/sdist, imports used throughout this repo and README (for example import ec_tools.database) will fail, which breaks consumers after publishing.

Useful? React with 👍 / 👎.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
colorama==0.4.6
pycryptodome==3.20.0
setuptools==69.5.1
1 change: 0 additions & 1 deletion scripts/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ rm -rf dist/ build/ *.egg-info .pytest_cache/
find . | grep -E "(/__pycache__$|/\.DS_Store$)" | xargs rm -rf
python3 -m build
pip3 install .

14 changes: 0 additions & 14 deletions setup.py

This file was deleted.

Loading