Skip to main content

Secure and extensible credential management SDK for Python applications.

Project description

🔐 infra-core-sdk

PyPI version Python License

🔐 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:

# See full version in 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

infra_core_sdk-0.2.0.post1.tar.gz (218.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

infra_core_sdk-0.2.0.post1-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file infra_core_sdk-0.2.0.post1.tar.gz.

File metadata

  • Download URL: infra_core_sdk-0.2.0.post1.tar.gz
  • Upload date:
  • Size: 218.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for infra_core_sdk-0.2.0.post1.tar.gz
Algorithm Hash digest
SHA256 6ecd17022040dc9e4bfb9b6f1320156a56458a20154da166466229ea80504e12
MD5 385096313e8c4521f02af17c4d6812c2
BLAKE2b-256 298a675cc1cf07144011c6fa12ba632a1c9c1bc6c742bd164e026a8932f7c259

See more details on using hashes here.

File details

Details for the file infra_core_sdk-0.2.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for infra_core_sdk-0.2.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 36201e930f561beab63ccca43ecffe89fa990f7c78e4b9b823b94ec2e504bf2b
MD5 a3323cb64df729f53f1a174cccc9ef00
BLAKE2b-256 a604f16bc654c7ad34c3832dcc23b9be9fa1192a401a53917cc888f7ef5d18c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page