Skip to main content

Configuration over convention.

Classy configuration:

>>> from stage import Conf
>>> class defaults:
... class SMTP:
...     ENABLED = False
...     TO = ''
...     SUBJECT = ''
...     # mail server
...     HOST = ''
...     # from email address
...     FROM = ''
...     AUTH = None
...     TLS = None
... class HTTP:
...     ENABLED = False
...     # web server host
...     HOST = ''
...     # web url
...     URL = ''
...     # http method
...     METHOD = 'GET'
... class SYSLOG:
...     ENABLED = False
...     # syslog host
...     HOST = 'localhost'
...     # syslog port
...     PORT = 514
...     # syslog facility
...     FACILITY = 'LOG_USER'
>>> class required:
... class LOG:
...     NAME = 'root'
...     # log level
...     LEVEL = 30  # warning
...     # default log formats
...     DATE = '%a, %d %b %Y %H:%M:%S'
...     # log entry format
...     ENTRY = (
...         '%(levelname)-4s -- %(asctime)s -- %(name)s: %(message)s'
...         ' (%(module)s.%(funcName)s at %(lineno)s)'
...     )
... class STREAM:
...     ENABLED = True
...     # redirect STDOUT to the logger?
...     STDOUT = True
...     # sets log level STDOUT is displayed under
...     LEVEL = 30  # warning
... class ROTATE:
...     ENABLED = False
...     # log file path
...     PATH = ''
...     # number of backups to keep
...     BACKUPS = 1
...     # interval to backup log file
...     INTERVAL = 'h'
...     ENCODING = None
...     MODE = 'a'
...     SIZE = 0
>>> config = Conf(defaults, required).freeze()
>>> config.LOG.NAME
'root'
>>> config.LOG.LEVEL
30
>>> config.LOG.DATE
'%a, %d %b %Y %H:%M:%S'
>>> config.STREAM.ENABLED
True

Telepathic environment configuration:

>>> from stage import TwoDeep, Env, env
>>> required = TwoDeep()
>>> with required.LOG:
... required.NAME('root')
... required.LEVEL(30)  # warning
... required.DATE('%a, %d %b %Y %H:%M:%S')
... required.ENTRY(
...     '%(levelname)-4s -- %(asctime)s -- %(name)s: %(message)s (%(mo'
...     'dule)s.%(funcName)s at %(lineno)s)'
... )
>>> with required.STREAM:
... required.ENABLED(True)
... required.STDOUT(True)
... required.LEVEL(30)  # warning
>>> with required.ROTATE:
... required.ENABLED(False)
... required.PATH('')
... required.BACKUPS(1)
... required.INTERVAL('h')
... required.ENCODING(None)
... required.MODE('a')
... required.SIZE(0)
>>> defaults = TwoDeep()
>>> with defaults.SMTP:
... defaults.ENABLED(False)
... defaults.TO('')
... defaults.SUBJECT('')
... defaults.HOST('')
... defaults.FROM('')
... defaults.AUTH(None)
... defaults.TLS(None)
>>> with defaults.HTTP:
... defaults.ENABLED(False)
... defaults.HOST('')
... defaults.URL('')
... defaults.METHOD('GET')
>>> with defaults.SYSLOG:
... defaults.ENABLED(False)
... defaults.HOST('localhost')
... defaults.PORT(514)
... defaults.FACILITY('LOG_USER')
>>> config = With(defaults, required).freeze()
>>> with config.LOG as LOG:
... LOG.NAME
... 'root'
... LOG.LEVEL
... 30
>>> with config.STREAM as STREAM:
... STREAM.LEVEL
... 30
... STREAM.STDOUT
... True
>>> with config.ROTATE as ROTATE:
... ROTATE.ENABLED
... False
... ROTATE.BACKUPS
... 1
... ROTATE.INTERVAL
... 'h'

Meanwhile, in some other module…

>>> from stage import env
>>> config = env()
>>> with config.LOG as LOG:
... LOG.LEVEL
... 30
... LOG.DATE
... '%a, %d %b %Y %H:%M:%S'
>>> with config.STREAM as STREAM:
... STREAM.ENABLED
... True
... STREAM.LEVEL
... 30
... STREAM.STDOUT
... True
>>> with config.ROTATE as ROTATE:
... ROTATE.ENABLED
... False
... ROTATE.BACKUPS
... 1
... ROTATE.INTERVAL
... 'h'

Spooky.

Metadata

Release files for stage 0.2.2

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

Source distributions (sdists)

Source distribution for stage 0.2.2
File Size Uploaded Provenance Actions
stage-0.2.2.zip 14.4 kB Without provenance Details for stage-0.2.2.zip
stage-0.2.2.tar.bz2 8.2 kB Without provenance Details for stage-0.2.2.tar.bz2

Release files / stage-0.2.2.zip

Download URL stage-0.2.2.zip
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ad7d29ff5e52d6fed058e621fdbd67a0e83e92e4af7d62049679b53cebf3459e
BLAKE2b-256 checksum
How to use checksums
83390fdb471133d7ea8fbc81a1ebcdc590b5ebe1aea30859a83262247b7d2bf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / stage-0.2.2.tar.bz2

Download URL stage-0.2.2.tar.bz2
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d1261a6585fe318f6baa0e242c0999ac81f22e47967581484be254036b9a140a
BLAKE2b-256 checksum
How to use checksums
15897d169a5706bf63ff732fa14e18c6d98185c6a5611dcb31264308960f164b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for stage 0.2.2

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.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files No provenance

0.0.1

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