Skip to main content

Use JSON files as if they're python modules

Project description

https://travis-ci.org/kragniz/json-sempai.png?branch=master https://pypip.in/version/json-sempai/badge.png?style=flat

Have you ever been kept awake at night, desperately feeling a burning desire to do nothing else but directly import JSON files as if they were python modules [1]? Now you can!

This abomination allows you to write

import some_json_file

and if some_json_file.json can be found, it will be available as if it is a python module.

Usage

Slap a json file somewhere on your python path. tester.json:

{
    "hello": "world",
    "this": {
        "can": {
            "be": "nested"
        }
    }
}

Now import jsonsempai and your json file!

>>> from jsonsempai import magic
>>> import tester
>>> tester
<module 'tester' from 'tester.json'>
>>> tester.hello
u'world'
>>> tester.this.can.be
u'nested'
>>>

Alternatively, a context manager may be used (100% less magic):

>>> import jsonsempai
>>> with jsonsempai.imports():
...     import tester
>>> tester
<module 'tester' from 'tester.json'>

Python packages are also supported:

$ tree
.
└── python_package
    ├── file.json
    ├── __init__.py
    └── nested_package
        ├── __init__.py
        └── second.json
>>> from jsonsempai import magic
>>> from python_package import file
>>> file
<module 'python_package.file' from 'python_package/file.json'>
>>> import python_package.nested_package.second
>>> python_package.nested_package.second
<module 'python_package.nested_package.second' from 'python_package/nested_package/second.json'>

Installing

Install from pip:

$ pip install json-sempai

or clone this repo and install from source:

$ python setup.py install

To purge this horror from your machine:

$ pip uninstall json-sempai

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

json-sempai-0.4.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

json_sempai-0.4.0-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file json-sempai-0.4.0.tar.gz.

File metadata

  • Download URL: json-sempai-0.4.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for json-sempai-0.4.0.tar.gz
Algorithm Hash digest
SHA256 33330ccf29646be5f533b692ab8c2a7790209c3e51a2b4778e8c382485774250
MD5 77b03027634ed962b9c0bd6317fc689b
BLAKE2b-256 cea3f3c3472e52e841f3dd9381704af5c9e737d8df1b17cda82e181f901d0462

See more details on using hashes here.

File details

Details for the file json_sempai-0.4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for json_sempai-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 37af2e80fc9bc910fe8ea1c5b3a9b4e712fccbb696c1bd8186cb8b2314cfaf97
MD5 3fbec91a96372dd5027f1f87ab2dca80
BLAKE2b-256 ca22745a03a600c4d5339d100f48aa98b24432ef20807427ce4877a16ae6b4fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page