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:

๐Ÿ‘‰ 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


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.1.tar.gz (218.0 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.1-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

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

Hashes for infra_core_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 639ddae23014675cc04965fbf62410aa240a5547d221b025a609e1f167dfcf23
MD5 fbabe7a03971acd19cf6e1517c819afc
BLAKE2b-256 dfabf23c4056c64eaac3a239c3d61e851295ce5ac198f85d17efd76dbdaa4fb5

See more details on using hashes here.

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

Hashes for infra_core_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01c8464beda14b78ce2cbf70db26a51ead7f46ada28fc5b67e4bce3661ae2c79
MD5 ae1fea9029dbccdc8410c4f809817d69
BLAKE2b-256 34ffc57c96dd9a008e24e005fac5d35c82e1537b761b487c3950861061d0bac2

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