Giter Club home page Giter Club logo

json-sempai's Introduction

json-sempai

https://travis-ci.org/kragniz/json-sempai.svg?branch=master

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
[1]Disclaimer: Only do this if you hate yourself and the rest of the world.

json-sempai's People

Contributors

borntyping avatar juanpabloaj avatar jwiggins avatar kragniz avatar qinusty avatar tcyrus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-sempai's Issues

Looks too legit

One of my co-workers suggested that we use this. I don't know if he's joking.
I hope he is.

I'm concerned that someone might be foolish enough to actually try to use this.

Possible resolution: move documentation pertaining to hating yourself and the world further up in the readme.
Other possible resolution: destroy this project and all references to it, removing it from github and pypi.

Save json files with query symbol in filename

Like:

  1. propertyValue--/uuid/.json?{{cacheBustUnitTest1}}/{{timeStamp}}

Load the URLs at the boot of your interface in a config or factory asynchronously. Then use $sce to parse the string and instantiate it as a template variable from environment variables of your app (timeStamp, etc.).

Rename to json-senpai

One does not simply use m without vowel after. The correct version is senpai, せんぱい.

Auto eval code strings

In my production server I keep needing to do:

def crud_handler():
    request = __import__('user_posted_json')
    eval(request.method)(db_connection, request.args)

Please consider allowing this syntax so my code looks cleaner:

def crud_handler():
    request = __import__('user_posted_json')
    request.method(db_connection, request.args)

I think adding a __call__ method on DottedDict that wraps eval should do it.

BSON Support

Needs to support BSON also, so we can do horrible dirty things like load Mongo data off disk, as a module, w/o a MongoDB server.

"ImportError: cannot import name tests"

I am a masochist. I cannot stop until I unleash this wretched beast and let it wreak havoc upon my world.

But for serious now, any idea why "pip install json-sempai" won't also download the "tests" directory? fyi, I'm on a windows machine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.