Skip to main content

Nano settings

Creates simple python config from environment variables. Smaller analog of pydantic-settings.

In comparison with pydantic-settings

Pros:

  • Easier to understand and support.
  • Relies only on standard library.
  • Uses dataclasses, not polluting your code with external types (if you're using approaches similar to clean architecture).
  • Almost no configuration.

Cons:

  • No validation, you have to do it yourself.
  • Almost no configuration.

Installation

pip install nano-settings

Basic usage

from dataclasses import dataclass

import nano_settings as ns


@dataclass
class DbSetup(ns.BaseConfig):
    max_sessions: int
    autocommit: bool = True


@dataclass
class Database(ns.BaseConfig):
    url: str
    timeout: int
    setup: DbSetup


# export MY_VAR__URL=https://site.com
# export MY_VAR__TIMEOUT=10
# export MY_VAR__SETUP__MAX_SESSIONS=2
config = ns.from_env(Database, env_prefix='my_var')
print(config)
# Database(timeout=10, url='https://site.com', setup=DbSetup(max_sessions=2, autocommit=True))

Supported variants

Straightforward - when your annotations are callable

from dataclasses import dataclass

import nano_settings as ns


@dataclass
class Config(ns.BaseConfig):
    variable: int
    # equivalent of
    # variable = int(os.getenv('VARIABLE'))

Annotated - when your annotations are complex and cannot be called

from dataclasses import dataclass
from typing import Annotated
import json

import nano_settings as ns


@dataclass
class Config(ns.BaseConfig):
    variable: Annotated[list[int], lambda x: x['key'], json.loads]
    # equivalent of
    # variable = json.loads(os.getenv('VARIABLE'))['key']

Nested - when your annotations are models

Example is listed in Basic usage

Aliases - when you want to get value by different name

Normal - try default and then alternatives

from dataclasses import dataclass
from typing import Annotated

import nano_settings as ns


@dataclass
class Config(ns.BaseConfig):
    variable: Annotated[str, ns.EnvAlias('OTHER')]
    # will try to get `VARIABLE` and then `OTHER`

Strict - try only alternatives

from dataclasses import dataclass
from typing import Annotated

import nano_settings as ns


@dataclass
class Config(ns.BaseConfig):
    variable: Annotated[str, ns.EnvAliasStrict('OTHER')]
    # will only try to get `OTHER`

Nullable - if null is also a valid value

from dataclasses import dataclass
from typing import Annotated

import nano_settings as ns


@dataclass
class Config(ns.BaseConfig):
    variable: Annotated[int | None, ns.Nullable(int)]

Choices - if you have a set of valid variants

from dataclasses import dataclass
from typing import Annotated

import nano_settings as ns


@dataclass
class Config(ns.BaseConfig):
  variable: Annotated[str, ns.Choices('one', 'two')]

Interval - when you have minimum and maximum (including)

from dataclasses import dataclass
from typing import Annotated

import nano_settings as ns


@dataclass
class Config(ns.BaseConfig):
  variable_1: Annotated[int, ns.Interval(1, 15)]
  variable_2: Annotated[float, ns.Interval(0.0, 0.6, cast=float)]

Boolean - when you're using true or false

from dataclasses import dataclass
from typing import Annotated

import nano_settings as ns


@dataclass
class Config(ns.BaseConfig):
  variable_1: Annotated[bool, ns.Boolean()]

Metadata

Release files for nano-settings 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nano-settings 0.1.3
File Size Uploaded Provenance Actions
nano_settings-0.1.3.tar.gz 10.6 kB Without provenance Details for nano_settings-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nano-settings 0.1.3
File Interpreter ABI Platform Actions
nano_settings-0.1.3-py3-none-any.whl Python 3 none any Details for nano_settings-0.1.3-py3-none-any.whl

Total release size: 19.7 kB

Release files / nano_settings-0.1.3.tar.gz

Download URL nano_settings-0.1.3.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6a0cb4ef98fd423bc4b52c1f05d6ab50be2ee9ddbb36975ac3026cb5aa7f723f
BLAKE2b-256 checksum
How to use checksums
afb8bb3049dec2ed65c0cd034e7ca8671d468987ece1d18e3fe9645f45cbe820
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.9

Release files / nano_settings-0.1.3-py3-none-any.whl

Download URL nano_settings-0.1.3-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f99123f63bc59ee5f940ca979be3813c80e19f60fe66e8e8b5252d4b7dfb7d02
BLAKE2b-256 checksum
How to use checksums
0904b5a1a3615f214a3730fb73e6093e93beae27a19785a6c6c6e9b8567aed7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.9

Security for nano-settings 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page