Lightweight high-performance wrapper for accessing camelCase python objects using snake_case syntax.
Project description
Slim. Beautiful. Snaked.
This package is also available for JavaScript on NPM as snaked-js
.
Snaked - Snakifying Your Code For PEP8
snaked-py
is a universal wrapper for Python objects of all kinds.
It allows you to access camelCase
and PascalCase
attributes of wrapped objects using
the familiar, and officially approved by the Python Software Foundation, snake_case
syntax.
Installation
You can install the latest stable release of snaked-py
using pip:
$ pip install snaked-py
You can also clone the GitHub repository and install the package manually by running:
$ python3 setup.py install
Features
- auto-enables snake_case access for camelCase objects
- autp-enables snake_case access for PascalCase objects
- wraps around any kind of object/3rd-party module/etc.
- includes runtime optimizations like caching
- PEP8-compliant and lightweight with only one dependency
Why should I use Snaked?
PEP8 (Python Enhancement Proposal 8, the official definition of Python coding standards) proposes the use of snake_case syntax throughout your code. However, it also states that consistency has more preference compared to PEP8 compliance.
If a 3rd-party module uses camelCase while you stick to to the official snake_case, you will have inconsistent code syntax which violates the PEP8. Using camelCase for all your code however, doesn't fully comply with PEP8 either.
Snaked
solves this problem by providing convenient wrapper utilities for accessing your
camelCase objects using the preferred snake_case syntax.
Example Usage
Let's use the following class in this example:
class Camel(object):
def createMe(self, name):
self.name = name
def sayHello(self):
print("Hey, I'm", self.name)
Usual access:
>>> animal = Camel()
>>> animal.createMe("Mr. C. Java")
>>> animal.sayHello()
Hey, I'm Mr. C. Java
Snaked Access:
>>> from snaked import Snaked
>>> animal = Snaked(Camel())
>>> animal.create_me("Mr. C. Python")
>>> animal.say_hello()
Hey, I'm Mr. C. Python
Edge Cases
Snaked uses resolution-caching by default to improve performance. In some rare situations, you might remove camelCase/pascalCase-attributes of your wrapped objects and re-introduce them in a different case.
Example:
>>> original = Camel()
>>> animal = Snaked(original)
>>> animal.create_me("Mr. Ed")
>>> animal.say_hello()
Hey, I'm Mr. Ed
>>> original.SayHello = original.sayHello
>>> del original.sayHello
>>> animal.say_hello()
AttributeError: 'Camel' object has no attribute 'sayHello'
You will then have to clear the resolution cache to let Snaked search again for the corresponding new camelCase/PascalCase/snake_case version:
>>> original.SayHello = original.sayHello
>>> del original.sayHello
>>> from snaked import clear_cache
>>> clear_cache(animal)
>>> animal.say_hello()
Hey, I'm Mr. Ed
You can also circumvent this situation by preventing Snaked from caching resolved attributes. Note however, that this will decrease your program's performance drastically.
animal = Snaked(original, use_cache=False)
License
This project is licensed under the MIT license by Squirrel-Preslash. It is free to use for any commercial or non-commercial purpose.
If you do so, you are required to include the full license text in a special section of your compiled program (i.e. in a credits or startup screen) or a copy of the license in the distributed source code.
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 Distribution
File details
Details for the file snaked-py-1.0.1.tar.gz
.
File metadata
- Download URL: snaked-py-1.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab25cb0eec5f816706fde1b07ba54e1d310bbceaf1d43da6fca5cd0e32e8b657 |
|
MD5 | 0e89a6d81ad80fcb9f06c688c4c6f65f |
|
BLAKE2b-256 | 4de286aef64408e01ef25be548acbb9c58da03698dcc00adea84305608c3ecac |
File details
Details for the file snaked_py-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: snaked_py-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d64def77f74c651240faf7d4e3ec234e86adb30ddcdd3bf30dba875455662cf9 |
|
MD5 | 82c42e39280903057cbdc9cc545c472d |
|
BLAKE2b-256 | 6051b08bdce09b0fdedae5677a850e1fd2eac3225d145d156e0a7ea862927f0f |