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.post0.tar.gz (26.7 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.post0-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file infra_core_sdk-0.2.1.post0.tar.gz.

File metadata

  • Download URL: infra_core_sdk-0.2.1.post0.tar.gz
  • Upload date:
  • Size: 26.7 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.post0.tar.gz
Algorithm Hash digest
SHA256 25e52aca4e7c6faeeb6008236dfc061fe6b6b9ba23d16f3c94e0e557ec56065f
MD5 ddc3d168fafd10e1e1ad76f038213d53
BLAKE2b-256 b6d4034d8b4c994d218d5f5bc0970bf87f74680b5d6d862153c7b301bbc34120

See more details on using hashes here.

File details

Details for the file infra_core_sdk-0.2.1.post0-py3-none-any.whl.

File metadata

File hashes

Hashes for infra_core_sdk-0.2.1.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9f91efd5f043279570766bdac75c33ea7af92b1ad827e0e64c1f9013fff85da
MD5 983e17033feac32fad45dc631df097d1
BLAKE2b-256 8d30dd754e4b60560e77acd88d7f5bd22a9515a5d9be499e44a2d13bf8eb3e9c

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