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.2.tar.gz (3.8 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.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsdc_loader-0.0.2.tar.gz
  • Upload date:
  • Size: 3.8 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.2.tar.gz
Algorithm Hash digest
SHA256 6f945e5cf9f870830610ee4e3683deadb76226b1f7f36c5033bd081ec03ff150
MD5 bbcd07dcc7690ede44c73f01c70441c4
BLAKE2b-256 55fb074c86e2fe8c98e4594e153d4c3ecaf37c2eb8c3bf2702a0b85fb3872be8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsdc_loader-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 151d04269a28813c9bbf92d1ce915cd2735ae7d8ec33b42f1280d3302cbf26fb
MD5 25829e628915662a4b2c28900bf843ef
BLAKE2b-256 1f93fadcab724123c37e3f02cd3fceb2683dd22ff121084f6d1a79c7c76edf6a

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