Secure and extensible credential management SDK for Python applications.
Project description
๐ infra-core-sdk
๐ infra-core-sdk
A production-ready SDK for:
- Root-aware path resolution
- Structured filesystem management
- Secure credential storage (encrypted)
- Pluggable encryption strategies
๐ Why this SDK exists
Managing paths, environments, and secrets across projects is hard.
This SDK solves:
- โ Hardcoded paths
- โ Environment inconsistencies
- โ Unsafe credential storage
- โ Scattered filesystem logic
โจ Core Features
- ๐ Root-aware path resolution
- ๐ Centralized path configuration
- ๐ Encrypted credential storage
- ๐ Multiple credential profiles
- โ๏ธ Pluggable encryption system
- ๐ง Deterministic filesystem behavior
๐ฆ Installation
pip install infra-core-sdk
๐ง Core Concepts (MUST READ)
๐น 1. Root Resolution
The SDK determines your project root using markers:
.git
pyproject.toml
requirements.txt
You can customize this.
๐น 2. Path System
Every path is defined using:
PathDefinition(path: str, use_root: bool)
| Type | Behavior |
|---|---|
use_root=True |
relative to project root |
use_root=False |
must be absolute |
๐น 3. Credentials Flow
SETUP:
โ generate key
โ encrypt data
โ store file
LOAD:
โ read key
โ decrypt data
โ return typed object
๐ Complete Example (Recommended Starting Point)
This is the canonical usage:
๐ https://github.com/rmcavalcante7/infra-core-sdk/blob/main/casos_de_uso/setup.py
๐งฉ Step-by-Step Usage
1๏ธโฃ Define your credentials model
from dataclasses import dataclass
from infra_core.credentials.models.base_credentials import BaseCredentials
@dataclass(frozen=True)
class MyCredentials(BaseCredentials):
api_token: str
2๏ธโฃ Configure ROOT behavior
from infra_core.core.root.root_config import RootConfig
from infra_core.core.root.root_config_provider import RootConfigProvider
config = RootConfig(
markers=(
".git",
"pyproject.toml",
)
)
RootConfigProvider.set(config)
3๏ธโฃ Configure Paths
from infra_core.core.path.path_config import PathConfig
from infra_core.core.path.path_config_provider import PathConfigProvider
from infra_core.core.path.path_definition import PathDefinition
from pathlib import Path
config = PathConfig()
# ROOT-based paths
config = config.addPath("secrets", PathDefinition("secrets", use_root=True))
config = config.addPath("secret_key", PathDefinition("secrets/key.key", use_root=True))
config = config.addPath("credentials", PathDefinition("secrets/{name}.json", use_root=True))
# Absolute path example
absolute_logs = str(Path.cwd() / "logs/app")
config = config.addPath(
"logs",
PathDefinition(absolute_logs, use_root=False),
)
PathConfigProvider.set(config)
4๏ธโฃ Setup credentials (ENCRYPT + SAVE)
from infra_core import CredentialsSetupService
from infra_core.security.fernet_encryption import FernetEncryption
setup = CredentialsSetupService(FernetEncryption)
setup.setup(
MyCredentials(api_token="123"),
name="default",
)
5๏ธโฃ Load credentials
from infra_core import CredentialsLoader
creds = CredentialsLoader.load(
MyCredentials,
FernetEncryption,
name="default",
)
print(creds.api_token)
๐ Generated Structure
project_root/
โโโ secrets/
โ โโโ key.key
โ โโโ default.json
๐ Multiple Credential Profiles
setup.setup(..., name="aws")
setup.setup(..., name="stripe")
setup.setup(..., name="internal")
๐ Path Management (Advanced)
Get resolved paths
from infra_core import PathManager
manager = PathManager()
print(manager.getPath("secrets"))
print(manager.getPath("credentials", name="default"))
Ensure directories exist
manager.ensurePathExists("secrets")
Delete files or directories
manager.deletePath("credentials", name="default")
๐ง Root Customization
Add / remove markers
from infra_core.core.root.root_config import RootConfig
from infra_core.core.root.root_config_provider import RootConfigProvider
config = RootConfig(markers=(".git", "pyproject.toml"))
RootConfigProvider.set(config)
Debug root resolution
from infra_core.core.root.root_resolver import RootResolver
print(RootResolver().resolve())
๐ Encryption
Default (recommended)
from infra_core.security.fernet_encryption import FernetEncryption
Custom encryption
class CustomEncryption:
def encrypt(self, value: str) -> str:
...
def decrypt(self, value: str) -> str:
...
โ ๏ธ Important Rules
โ Do NOT manually manage keys
Fernet.generate_key()
โ Always use setup service
CredentialsSetupService(...)
โ Do NOT use relative paths with use_root=False
PathDefinition("logs", use_root=False) # INVALID
โ Use absolute paths
PathDefinition(str(Path.cwd() / "logs"), use_root=False)
๐งช Development
pip install -e .[dev]
pytest
mypy src/
black .
๐ง Architecture Overview
core/
path/
root/
credentials/
service
loader
setup
security/
encryption
๐ฆ Build & Publish
python -m build
twine check dist/*
๐ License
MIT
๐จโ๐ป Author
Rafael Cavalcante
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file infra_core_sdk-0.2.1.tar.gz.
File metadata
- Download URL: infra_core_sdk-0.2.1.tar.gz
- Upload date:
- Size: 218.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
639ddae23014675cc04965fbf62410aa240a5547d221b025a609e1f167dfcf23
|
|
| MD5 |
fbabe7a03971acd19cf6e1517c819afc
|
|
| BLAKE2b-256 |
dfabf23c4056c64eaac3a239c3d61e851295ce5ac198f85d17efd76dbdaa4fb5
|
File details
Details for the file infra_core_sdk-0.2.1-py3-none-any.whl.
File metadata
- Download URL: infra_core_sdk-0.2.1-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01c8464beda14b78ce2cbf70db26a51ead7f46ada28fc5b67e4bce3661ae2c79
|
|
| MD5 |
ae1fea9029dbccdc8410c4f809817d69
|
|
| BLAKE2b-256 |
34ffc57c96dd9a008e24e005fac5d35c82e1537b761b487c3950861061d0bac2
|