Skip to content

Instantly share code, notes, and snippets.

View 7576457's full-sized avatar

Islam Asabaev 7576457

  • North Caucasus
  • 10:02 (UTC +03:00)
View GitHub Profile
@7576457
7576457 / env.py
Last active February 4, 2026 10:05
import os
def load_env_vars(path: str) -> None:
with open(path) as file:
for line in file.readlines():
data = list(map(lambda v: v.strip(), line.split("=")))
variable, value = data[0], data[1]
os.environ[variable] = value
from typing import Any, Self
from .value_object import ValueObject
class Entity[T: ValueObject]:
"""Base class for mutable entities (Entity) in the domain model.
A mutable object that preserves its identity
throughout its lifecycle, despite changes to its attributes.
Every entity has the following properties:
from dataclasses import dataclass, fields
from typing import Any, Self
@dataclass(frozen=True, slots=True, repr=False)
class ValueObject:
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
if cls is ValueObject:
raise Exception("ValueObject cannot be instantiated directly!")
if not fields(cls):