Global accessors for things like settings. This could be used across applications and modules to share data.
Project description
Global accessors for things like settings. This could be used across applications and modules to share data.
This utility is to help easily share values across multiple modules and libraries without having to pass values around.
Example
Simple example.
# settings.py
import pyglobal
pyglobal.set('abc', 123)
pyglobal.default('qwerty', '')
pyglobal.set('Hello', 'World!')
pyglobal.default('SECRET_KEY', '!!!CHANGE!!!') # Warning: Any library using pyglobal could then look for this value.
pyglobal.set('DATABASE_URL', 'http://') # Warning: Any library using pyglobal could then look for this value.
Then use the settings in another part of the project
# main.py
import pyglobal
import settings # Set pyglobal values before using in other modules
import db
app = App(SECRET_KEY=pyglobal.get('SECRET_KEY'))
The sub module db.py doesn’t have to know anything about settings.py and can be nested down packages.
# db.py
import pyglobal
db = Database(pyglobal.get('DATABASE_URL'))
Avoiding clashes with other projects
Avoid clashes and add some small amount of security to your app with a scope
# settings.py
import pyglobal
import uuid
app_scope = 'MYAPP=' + str(uuid.uuid4())
def scope_get(key, default=None):
return pyglobal.get(key, default, app_scope)
def scope_set(key, value)
return pyglobal.set(key, value, app_scope)
pyglobal.scope_get = scope_get
pyglobal.scope_set = scope_set
pyglobal.set('SECRET_KEY', '!! Change !!', scope=app_scope)
scope_set('DATABASE_URL', 'http://')
Once again you can use in other files, but you would also need the scope to access.
# main.py
import pyglobal
import settings
secret = pyglobal.scope_get('SECRET_KEY')
db_url = pyglobal.get('DATABASE_URL', scope=settings.app_scope)
At some point code can always be disassembled, so this isn’t really secure. All scopes are is another level of obfuscation and a way to avoid global names from clashing with other projects.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pyglobal-0.0.1.tar.gz
.
File metadata
- Download URL: pyglobal-0.0.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59d07da0d555e76ab512db305fa91d14c3a540c1b03b797dbd06a5cc1e29fc92 |
|
MD5 | 4abc63bc37ceb243e9aff71bdd10a588 |
|
BLAKE2b-256 | 7321c61da59073afe14a82d18c0afae397458c709b06999dc8179d6326d2ed9d |
File details
Details for the file pyglobal-0.0.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: pyglobal-0.0.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 20.7 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97a7511916df379f2d77df45b183b91fe8824d6c0973711c678f4c380e0fc3b0 |
|
MD5 | 281a7be9434b79ab063d772ce4ab2059 |
|
BLAKE2b-256 | 863902ecbe6872f0e5838720ea8440748406ca2bc7010548db4b30aa02284a93 |
File details
Details for the file pyglobal-0.0.1-cp38-cp38-win32.whl
.
File metadata
- Download URL: pyglobal-0.0.1-cp38-cp38-win32.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f500597665271bbf5dc81cfe264ac4abe47b978a67d1643ed06e3586ba10ee5 |
|
MD5 | 164ebd2e5de9115af582f7a032b6aea0 |
|
BLAKE2b-256 | ad74c50da6e38e2f0250b9724ae91803e25e195bba2a27887739cce61e49967e |
File details
Details for the file pyglobal-0.0.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: pyglobal-0.0.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 32.0 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 733283f6ad279d5b19a400319b97cb19689a411f2ffe34864f216a1b615ec53d |
|
MD5 | 8ce26a073682a31202038e571dab33a4 |
|
BLAKE2b-256 | ef728ef191646ce91c02d053b98e4588a2a916e8c70172f20280736fe56e9564 |
File details
Details for the file pyglobal-0.0.1-cp37-cp37m-win32.whl
.
File metadata
- Download URL: pyglobal-0.0.1-cp37-cp37m-win32.whl
- Upload date:
- Size: 37.3 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e93fbc686fc5522ffef85e0314b2bbb24e9586fe19491685b4266af301baf7b7 |
|
MD5 | c6aa8d0b1582b2c4e4e0fcc4d73e1e1b |
|
BLAKE2b-256 | b83f1c4fdab39520cada5024ab20b5d672d2f2ed4ba164b9d87f29f7d6d786de |
File details
Details for the file pyglobal-0.0.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: pyglobal-0.0.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 43.3 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f023eb5aa4eb9cce01e23431ac5220b07a8d869805949028cf0b9ef19355a74 |
|
MD5 | 50a435ce5d310753a124a5bf1bc0fd94 |
|
BLAKE2b-256 | 5085568f072d0b843b207346d11f55202b12ea9f743ec8557b01e4df232396f5 |
File details
Details for the file pyglobal-0.0.1-cp36-cp36m-win32.whl
.
File metadata
- Download URL: pyglobal-0.0.1-cp36-cp36m-win32.whl
- Upload date:
- Size: 48.6 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85f8a1fbf5b9caf684561b2af201f3e07fb893ccefbaf7df76fd4c4904803765 |
|
MD5 | 3cf2f03fae9d349d9943d79b733fb58b |
|
BLAKE2b-256 | eeb263f46dd7a762cbcd6ab51b6bff1c33189eafe5d1f224942bf6941ca5700d |
File details
Details for the file pyglobal-0.0.1-cp34-cp34m-win_amd64.whl
.
File metadata
- Download URL: pyglobal-0.0.1-cp34-cp34m-win_amd64.whl
- Upload date:
- Size: 52.6 kB
- Tags: CPython 3.4m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a7d4664abfa97f3f150d8fffab4d262fcd73b37f8e30ca4ea60e5cf2777f27a |
|
MD5 | b0948d1a4348a4982012883ab79f70ea |
|
BLAKE2b-256 | 92d464fd220d54a351f41732484373420c709f56f030be213da82f0560d8021c |
File details
Details for the file pyglobal-0.0.1-cp34-cp34m-win32.whl
.
File metadata
- Download URL: pyglobal-0.0.1-cp34-cp34m-win32.whl
- Upload date:
- Size: 52.6 kB
- Tags: CPython 3.4m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89df9e8c8783ab9fefa77f582dce0816056c89a21e0144ba5f890c336e32e9af |
|
MD5 | da6daa27fa8edd4f6f695f87d9638673 |
|
BLAKE2b-256 | 21b92e67164651ad90c96d98f1db02db5e5c47257b60b66aec31116e1118540b |