Skip to main content

JSON Data Class Loader

Project description

JSDC Loader (JSON Data Class Loader)

JSDC Loader is a Python utility for loading JSON configuration files into dataclass objects. It provides a simple and type-safe way to manage configuration data in your Python applications by forcing the use of dataclass and type hinting.

Features

  • Load JSON configuration files into dataclass objects
  • Support for nested dataclass structures
  • Type checking and conversion for configuration values
  • Easy updating of configuration from different files
  • Ability to dump modified configurations back to JSON

Installation

To install JSDC Loader, you can use pip:

pip install jsdc_loader

Usage

Here's an example of how to use JSDC Loader:

Example 1

from dataclasses import dataclass
from jsdc_loader import JSDC_Loader

@dataclass
class DatabaseConfig:
    host: str = 'localhost' # default value must be provided
    port: int = 3306
    user: str = 'root'
    password: str = 'password'


config = JSDC_Loader('config.json', DatabaseConfig)
print(config.host)

Example 2

from dataclasses import dataclass, field
from jsdc_loader import JSDC_Loader

# Database Config ...

@dataclass
class UserConfig:
    name: str = 'John Doe'
    age: int = 30

@dataclass
class AppConfig:
    user: UserConfig = field(default_factory=lambda: UserConfig())
    database: DatabaseConfig = field(default_factory=lambda: DatabaseConfig())

config = JSDC_Loader('config.json', AppConfig)
print(config.user.name)

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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

jsdc_loader-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsdc_loader-0.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file jsdc_loader-0.0.1.tar.gz.

File metadata

  • Download URL: jsdc_loader-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for jsdc_loader-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3332ab889af7fb9ecb9eb5b246e2495fb15245d3a2996709abc02e3c9d219abd
MD5 5be9c47b276aa2c189e10edb7671b249
BLAKE2b-256 d9881c7a83e9a0093c596bca41a755df385a2e22b0efa5a1d7e78ed93e0b7def

See more details on using hashes here.

File details

Details for the file jsdc_loader-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: jsdc_loader-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for jsdc_loader-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8f36476a7d6298d5f306a0449258d457ae47572355acc3732ae9ff3c4a33af7
MD5 42ed031364596e2e7c5b4850146e8efe
BLAKE2b-256 e9f1683082126f02003e3aad4d0fabcb021a8ef2d4c7e943b589a86bed1b82aa

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