Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kragniz/json-sempai
Use JSON files as if they are python modules
https://github.com/kragniz/json-sempai
don-t python stupid this use
Last synced: 19 days ago
JSON representation
Use JSON files as if they are python modules
- Host: GitHub
- URL: https://github.com/kragniz/json-sempai
- Owner: kragniz
- License: mit
- Created: 2014-12-30T06:24:41.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-09-26T12:14:02.000Z (about 3 years ago)
- Last Synced: 2024-10-01T00:41:04.558Z (about 1 month ago)
- Topics: don-t, python, stupid, this, use
- Language: Python
- Homepage:
- Size: 38.1 KB
- Stars: 1,252
- Watchers: 32
- Forks: 53
- Open Issues: 12
-
Metadata Files:
- Readme: README.rst
- License: COPYING
Awesome Lists containing this project
- my-awesome-starred - json-sempai - Use JSON files as if they are python modules (Python)
- starred-awesome - json-sempai - Use JSON files as if they are python modules (Python)
README
===========
json-sempai
===========.. image:: https://travis-ci.org/kragniz/json-sempai.svg?branch=master
:target: https://travis-ci.org/kragniz/json-sempai.. image:: https://img.shields.io/pypi/v/json-sempai.svg
:target: https://pypi.python.org/pypi/json-sempaiHave 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
[#]_? Now you can!This abomination allows you to write
.. code:: python
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``:
.. code:: json
{
"hello": "world",
"this": {
"can": {
"be": "nested"
}
}
}Now import jsonsempai and your json file!
.. code:: python
>>> from jsonsempai import magic
>>> import tester
>>> tester
>>> tester.hello
u'world'
>>> tester.this.can.be
u'nested'
>>>Alternatively, a context manager may be used (100% less magic):
.. code:: python
>>> import jsonsempai
>>> with jsonsempai.imports():
... import tester
>>> tester
Python packages are also supported:
.. code:: bash
$ tree
.
└── python_package
├── file.json
├── __init__.py
└── nested_package
├── __init__.py
└── second.json.. code:: python
>>> from jsonsempai import magic
>>> from python_package import file
>>> file
>>> import python_package.nested_package.second
>>> python_package.nested_package.second
Installing
----------Install from pip:
.. code:: bash
$ pip install json-sempai
or clone this repo and install from source:
.. code:: bash
$ python setup.py install
To purge this horror from your machine:
.. code:: bash
$ pip uninstall json-sempai
.. [#] Disclaimer: Only do this if you hate yourself and the rest of the world.