• Stars
    star
    1,253
  • Rank 37,239 (Top 0.8 %)
  • Language
    Python
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use JSON files as if they are python modules

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.

More Repositories

1

tor-controller

Run Tor onion services on Kubernetes
Go
534
star
2

python-etcd3

Python client for the etcd API v3
Python
422
star
3

anyprint

Use any* language's print statements in Python
Python
403
star
4

cookiecutter-pypackage-minimal

A minimal template for python packages
Python
200
star
5

omochabako

Toy container runtime, capable of running docker images
Python
67
star
6

pam-2fa-scream

Highly secure second factor auth by screaming at your computer.
C
17
star
7

typejudge

Automated semver compliance based on type hints
Python
16
star
8

whalie

Jimble your while loops.
Python
15
star
9

python-pixiv

Pixiv API client for python
Python
13
star
10

tor-ingress-controller

An ingress controller to expose kubernetes services as onion services on the tor network
Go
12
star
11

reddit-auto-respond

Responds to privates messages on reddit
Python
11
star
12

doot

๐Ÿ’€ tฬทhอeฬด sฬถkeฬกlอœtalอž ๐Ÿ’€ of keฬขrnฬ•eอขl ๐Ÿ’€
C
10
star
13

nixbot

Python
8
star
14

configuration.nix

NixOS configuration files
Nix
8
star
15

CMPS10

Arduino library for the CMPS10 compass
C++
5
star
16

toot

Mastodon API client for Go
Go
5
star
17

inidiff

Find the differences between two ini files
Python
4
star
18

dot-files

Some config files
Perl
4
star
19

librowind

C library for the RO Wind sensor
C
4
star
20

amnesiafs

C
3
star
21

containers

Easily manipulate app containers
Python
2
star
22

soilmaker

Makes pictures of soil
Python
2
star
23

anon-ircd

Python
2
star
24

comfc

The comfy compositor
C
2
star
25

lode

Tiny and minimalistic logging utility module
Python
2
star
26

java-player

Mirror of the javaclient3 branch of java-player
Java
2
star
27

hyoki

Go
2
star
28

christmas-eval

Python
2
star
29

piebook

A small console-based ebook reader written in python
Python
2
star
30

computing

Random stuff with python
Python
1
star
31

github-setup-irc-notifications

Configure all repositories in an organization with irc notifications
Python
1
star
32

musc

Small music playing server
Python
1
star
33

fpc-stuff

some rather rancid fpc projects
Pascal
1
star
34

betamax-yaml-serializer

YAML serializer for betamax
Python
1
star
35

gpsts

Attempts to sync system and GPS time
Python
1
star
36

m8

1
star
37

pypmon

ip address monitor
Python
1
star
38

mushroom

Mirror of https://git.sr.ht/~kragniz/mushroom
C
1
star
39

llgc

Python
1
star
40

nyaa-scrobble

Scrobbles music from nyaa-radio
Python
1
star
41

prettytable

Automatically exported from code.google.com/p/prettytable
Python
1
star
42

sails-fedora

1
star
43

wch

Small mplayer wrapper which allows restarting from the episode last watched
Python
1
star
44

proxy

Go
1
star
45

hexogen

tile based declarative texture synthesis
Python
1
star
46

sudoku-solver

Simple non-backtracking sudoku solver
Java
1
star
47

pygamebook

Makes nice looking game books
Python
1
star
48

pixiv-bot-demo

Python
1
star
49

pychi

py can has internet - check if this machine is connected to the world wide web
Python
1
star
50

nduko

n by n suduko
Python
1
star