ezjsonpy


Nameezjsonpy JSON
Version 1.0.5 PyPI version JSON
download
home_pageNone
SummaryPython library that allows you to easily load languages and settings ​​into your project using JSON files
upload_time2024-09-04 05:43:11
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6
licenseMIT License
keywords language settings python json
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # EzJsonPy
EzJsonPy is a Python library for loading and managing languages ​​and settings in JSON format.

## Installation

To install ezjsonpy, simply use the pip install command

```bash
pip install ezjsonpy
```

## Usage

### Simple use of language functions.
You need the language files in your project in their respective path

```py
from ezjsonpy import (
    load_language,
    load_languages,
    set_language,
    translate_message,
    get_current_language,
    get_languages
)

# Load a single language
load_language('en', 'path/to/en.json')

# Load multiple languages
languages = [
    {'name': 'en', 'path': 'path/to/en.json'},
    {'name': 'es', 'path': 'path/to/es.json'}
]
load_languages(languages)

# Set the current language
set_language('en')

# Translate a message
message = translate_message('greeting.hello')
print(message)  # Output: Hello (if the translation exists in en.json)

# Get the current language
current_language = get_current_language()
print(current_language)  # Output: en

# Get all loaded languages
loaded_languages = get_languages()
print(loaded_languages)  # Output: {'en': {...}, 'es': {...}}
```

### You can load the language in the main file and get the translations in other files.


#### main.py

```py
from ezjsonpy import load_language, set_language
from test import example_function

load_language('en', 'en.json')
set_language('en')
example_function()
```

##### test.py

```py
from ezjsonpy import translate_message

def example_function():
    print(translate_message('helloWorld'))  # Output: Hello World
    print(translate_message('messages.example'))  # Output: Example Message
```

#### en.json

```json
{
    "messages": {
        "example": "Example Message"
    },
    "helloWorld": "Hello World"
}
```

#### Complete documentation of language features [here](./docs/language.md)

### Simple use of settings functions.
You need the setting file in your project in their respective path

```py
from ezjsonpy import (
    load_configuration,
    load_configurations,
    get_config_value,
    set_config_value,
    get_configuration,
    get_configurations,
    remove_configuration,
    remove_all_configurations
)

# Load a single configuration
load_configuration('config1', 'path/to/config1.json')

# Load multiple configurations
configs = [
    {'name': 'config1', 'path': 'path/to/config1.json'},
    {'name': 'config2', 'path': 'path/to/config2.json'}
]
load_configurations(configs)

# Get a value from a configuration
value = get_config_value('some.key', 'config1')
print(f"Value from config1: {value}")

# Set a value in a configuration
set_config_value('some.key', 'new_value', 'config1')

# Verify the value was set
updated_value = get_config_value('some.key', 'config1')
print(f"Updated value from config1: {updated_value}")

# Get the loaded configuration
config = get_configuration('config1')
print(f"Loaded config1: {config}")

# Get all loaded configurations
all_configs = get_configurations()
print(f"All loaded configurations: {all_configs}")

# Remove a specific configuration
remove_configuration('config1')
print(f"Configurations after removing config1: {get_configurations()}")

# Remove all configurations
remove_all_configurations()
print(f"Configurations after removing all: {get_configurations()}")
```

### Like the language, you can load the configuration in your main file and in the modules get the configuration directly

#### main.py

```py
from ezjsonpy import load_configuration
from test import example_function

load_configuration('default', 'config.json')
load_configuration('anotherConfig', 'anotherConfig.json')
example_function()
```

##### test.py

```py
from ezjsonpy import get_config_value


def example_function():
    print(get_config_value('key1', 'default'))  # Output: 'defaultValue'
    print(get_config_value('key1'))  # Default config_name is 'default'. Output: 'defaultValue'
    print(get_config_value('key2', 'anotherConfig'))  # Output: 'anotherValue'
```

#### config.json

```json
{
    "key1": "defaultValue"
}
```

#### anotherConfig.json

```json
{
    "key2": "anotherValue"
}
```

#### Complete documentation of language features [here](./docs/settings.md)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ezjsonpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "language, settings, python, json",
    "author": null,
    "author_email": "\"Pedro Agustin Vega (wrrulos)\" <pedroagustinvega04@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b1/6d/1559fa9351ae4b1fda0dc7e87254fe018ac6832b240f36bf588ce897e633/ezjsonpy-1.0.5.tar.gz",
    "platform": null,
    "description": "# EzJsonPy\r\nEzJsonPy is a Python library for loading and managing languages \u200b\u200band settings in JSON format.\r\n\r\n## Installation\r\n\r\nTo install ezjsonpy, simply use the pip install command\r\n\r\n```bash\r\npip install ezjsonpy\r\n```\r\n\r\n## Usage\r\n\r\n### Simple use of language functions.\r\nYou need the language files in your project in their respective path\r\n\r\n```py\r\nfrom ezjsonpy import (\r\n    load_language,\r\n    load_languages,\r\n    set_language,\r\n    translate_message,\r\n    get_current_language,\r\n    get_languages\r\n)\r\n\r\n# Load a single language\r\nload_language('en', 'path/to/en.json')\r\n\r\n# Load multiple languages\r\nlanguages = [\r\n    {'name': 'en', 'path': 'path/to/en.json'},\r\n    {'name': 'es', 'path': 'path/to/es.json'}\r\n]\r\nload_languages(languages)\r\n\r\n# Set the current language\r\nset_language('en')\r\n\r\n# Translate a message\r\nmessage = translate_message('greeting.hello')\r\nprint(message)  # Output: Hello (if the translation exists in en.json)\r\n\r\n# Get the current language\r\ncurrent_language = get_current_language()\r\nprint(current_language)  # Output: en\r\n\r\n# Get all loaded languages\r\nloaded_languages = get_languages()\r\nprint(loaded_languages)  # Output: {'en': {...}, 'es': {...}}\r\n```\r\n\r\n### You can load the language in the main file and get the translations in other files.\r\n\r\n\r\n#### main.py\r\n\r\n```py\r\nfrom ezjsonpy import load_language, set_language\r\nfrom test import example_function\r\n\r\nload_language('en', 'en.json')\r\nset_language('en')\r\nexample_function()\r\n```\r\n\r\n##### test.py\r\n\r\n```py\r\nfrom ezjsonpy import translate_message\r\n\r\ndef example_function():\r\n    print(translate_message('helloWorld'))  # Output: Hello World\r\n    print(translate_message('messages.example'))  # Output: Example Message\r\n```\r\n\r\n#### en.json\r\n\r\n```json\r\n{\r\n    \"messages\": {\r\n        \"example\": \"Example Message\"\r\n    },\r\n    \"helloWorld\": \"Hello World\"\r\n}\r\n```\r\n\r\n#### Complete documentation of language features [here](./docs/language.md)\r\n\r\n### Simple use of settings functions.\r\nYou need the setting file in your project in their respective path\r\n\r\n```py\r\nfrom ezjsonpy import (\r\n    load_configuration,\r\n    load_configurations,\r\n    get_config_value,\r\n    set_config_value,\r\n    get_configuration,\r\n    get_configurations,\r\n    remove_configuration,\r\n    remove_all_configurations\r\n)\r\n\r\n# Load a single configuration\r\nload_configuration('config1', 'path/to/config1.json')\r\n\r\n# Load multiple configurations\r\nconfigs = [\r\n    {'name': 'config1', 'path': 'path/to/config1.json'},\r\n    {'name': 'config2', 'path': 'path/to/config2.json'}\r\n]\r\nload_configurations(configs)\r\n\r\n# Get a value from a configuration\r\nvalue = get_config_value('some.key', 'config1')\r\nprint(f\"Value from config1: {value}\")\r\n\r\n# Set a value in a configuration\r\nset_config_value('some.key', 'new_value', 'config1')\r\n\r\n# Verify the value was set\r\nupdated_value = get_config_value('some.key', 'config1')\r\nprint(f\"Updated value from config1: {updated_value}\")\r\n\r\n# Get the loaded configuration\r\nconfig = get_configuration('config1')\r\nprint(f\"Loaded config1: {config}\")\r\n\r\n# Get all loaded configurations\r\nall_configs = get_configurations()\r\nprint(f\"All loaded configurations: {all_configs}\")\r\n\r\n# Remove a specific configuration\r\nremove_configuration('config1')\r\nprint(f\"Configurations after removing config1: {get_configurations()}\")\r\n\r\n# Remove all configurations\r\nremove_all_configurations()\r\nprint(f\"Configurations after removing all: {get_configurations()}\")\r\n```\r\n\r\n### Like the language, you can load the configuration in your main file and in the modules get the configuration directly\r\n\r\n#### main.py\r\n\r\n```py\r\nfrom ezjsonpy import load_configuration\r\nfrom test import example_function\r\n\r\nload_configuration('default', 'config.json')\r\nload_configuration('anotherConfig', 'anotherConfig.json')\r\nexample_function()\r\n```\r\n\r\n##### test.py\r\n\r\n```py\r\nfrom ezjsonpy import get_config_value\r\n\r\n\r\ndef example_function():\r\n    print(get_config_value('key1', 'default'))  # Output: 'defaultValue'\r\n    print(get_config_value('key1'))  # Default config_name is 'default'. Output: 'defaultValue'\r\n    print(get_config_value('key2', 'anotherConfig'))  # Output: 'anotherValue'\r\n```\r\n\r\n#### config.json\r\n\r\n```json\r\n{\r\n    \"key1\": \"defaultValue\"\r\n}\r\n```\r\n\r\n#### anotherConfig.json\r\n\r\n```json\r\n{\r\n    \"key2\": \"anotherValue\"\r\n}\r\n```\r\n\r\n#### Complete documentation of language features [here](./docs/settings.md)\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Python library that allows you to easily load languages and settings \u200b\u200binto your project using JSON files",
    "version": "1.0.5",
    "project_urls": {
        "documentation": "https://github.com/pedroagustinvega/ezjsonpy",
        "homepage": "https://github.com/pedroagustinvega/ezjsonpy",
        "repository": "https://github.com/pedroagustinvega/ezjsonpy"
    },
    "split_keywords": [
        "language",
        " settings",
        " python",
        " json"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0cd81b71a0f7fec6202d55bcc1541c10b98ca5bc13890169db518cb7cdd69d87",
                "md5": "59a55913043fe4b26148d0312ef1e67c",
                "sha256": "0ec148bf83860ef45c67a4fbfef153af5bab8b7ec8975006ad3fe08dc33b4a72"
            },
            "downloads": -1,
            "filename": "ezjsonpy-1.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "59a55913043fe4b26148d0312ef1e67c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7301,
            "upload_time": "2024-09-04T05:43:10",
            "upload_time_iso_8601": "2024-09-04T05:43:10.148678Z",
            "url": "https://files.pythonhosted.org/packages/0c/d8/1b71a0f7fec6202d55bcc1541c10b98ca5bc13890169db518cb7cdd69d87/ezjsonpy-1.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b16d1559fa9351ae4b1fda0dc7e87254fe018ac6832b240f36bf588ce897e633",
                "md5": "8e12a6602a68cc2e319a91cdcd089b42",
                "sha256": "e63b485c52c3442697c8c369a9b4457b61d97d308a2828f69826cfb74a77deb6"
            },
            "downloads": -1,
            "filename": "ezjsonpy-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "8e12a6602a68cc2e319a91cdcd089b42",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 8741,
            "upload_time": "2024-09-04T05:43:11",
            "upload_time_iso_8601": "2024-09-04T05:43:11.572288Z",
            "url": "https://files.pythonhosted.org/packages/b1/6d/1559fa9351ae4b1fda0dc7e87254fe018ac6832b240f36bf588ce897e633/ezjsonpy-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-04 05:43:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pedroagustinvega",
    "github_project": "ezjsonpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ezjsonpy"
}
        
Elapsed time: 0.48579s