Skip to main content

A Python library full of useful Python tools.

Project description

Viper

A Python library full of useful Python tools.

Viper adds many missing tools and improves many existing tools in Python. For example, this includes frozendicts, a more advanced IO interface, improved ABCs, debugging tools, new decorators, types of classes, even new types of modules, etc. It is designed to feel very Python-like.

To list all of the available packages, simply Python's interactive prompt and explore:

>>> from Viper import *
>>> import Viper
>>> dir(Viper)
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'abc', 'debugging', 'exceptions', 'format', 'frozendict', 'interactive', 'io', 'meta', 'pickle_utils', 'warnings']
>>> help(io)
Help on module Viper.io in Viper:

NAME
    Viper.io - This module adds some useful IO tools. This includes IO buffer and pipe/circular buffers for both bytes and strings.

CLASSES
    Viper.abc.io.BytesIO(Viper.abc.io.BytesReader, Viper.abc.io.BytesWriter, Viper.abc.io.IO)
        BytesBuffer
        BytesIO
    Viper.abc.io.StringIO(Viper.abc.io.StringReader, Viper.abc.io.StringWriter, Viper.abc.io.IO)
        StringBuffer
        StringIO

    class BytesBuffer(Viper.abc.io.BytesIO)
...

Some practical and classical examples of the content of Viper include:

  • Making iterable classes:
>>> class MyClass(metaclass = Viper.meta.iterable.InstanceReferencingClass):
...     pass
... 
>>> c = MyClass()
>>> list(MyClass)[0] is c
True
>>> del c
>>> len(list(MyClass))
0

This is useful for classes for which you want to keep track of the instances or for which you need to perform some operations on.

  • Timing function calls and generate performance reports:
>>> c = Viper.debugging.chrono.Chrono()
>>> @c
... def fibo(n):
...     if n <= 0:
...         return 0
...     if n == 1:
...         return 1
...     return fibo(n - 1) + fibo(n - 2)
...
>>> fibo(25)
75025
>>> Viper.debugging.chrono.print_report(c)
Execution report featuring 1 functions or methods, over 375ms.
Per function results :
Function __main__.fibo
        Calls : 242785, Total :   375ms   , Average : 1µs, 545ns, Proportion : 100.0% of the time

You can use one Chrono object on multiple functions. It becomes useful if you need to know what part of your code you should optimize first.

  • Flux operators:
>>> buffer = Viper.io.BytesIO()
>>> buffer << Viper.pickle_utils.StreamPickler("This is a test object")
>>> buffer.seek(0)
0
>>> Viper.pickle_utils.StreamUnpickler() << buffer
'This is a test object'

Flux operator define a much stronger, safer and handy interface than Python IOs. Furthermore, this syntax is revertible and stackable for constants:

>>> buffer = Viper.io.StringIO()
>>> "Good!\n" >> (buffer << "Hello!\n" << "How are you doing?\n")
<Viper.io.StringIO object at 0x000002A2F862E4A0>
>>> buffer.seek(0)
0
>>> buffer.readable
Budget(32)
>>> print(buffer.read(buffer.readable.value))
Hello!
How are you doing?
Good!
  • And many other useful random features!

Note that this library is extensively documented. Use Python's help system (for example the help function while in an interactive interpreter) to learn how to use all the modules and classes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

viper_lib-1.5.2.tar.gz (53.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

viper_lib-1.5.2-py3-none-any.whl (65.0 kB view details)

Uploaded Python 3

File details

Details for the file viper_lib-1.5.2.tar.gz.

File metadata

  • Download URL: viper_lib-1.5.2.tar.gz
  • Upload date:
  • Size: 53.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for viper_lib-1.5.2.tar.gz
Algorithm Hash digest
SHA256 ae3abaddefd4694a91e0952eab4f892e9f49ca81ac3993751e8adb577275cc29
MD5 1f11cf6da128eb938273e00e0598f369
BLAKE2b-256 a2ccd729dc160e49127d2e0ec43cef8fb8727dc6c0cbb7fa8f340f9d85285a3c

See more details on using hashes here.

File details

Details for the file viper_lib-1.5.2-py3-none-any.whl.

File metadata

  • Download URL: viper_lib-1.5.2-py3-none-any.whl
  • Upload date:
  • Size: 65.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for viper_lib-1.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 079d4843764f8c12c53029181e6e9549e9c80960cca2c5a1b6aa94fb18e928f3
MD5 f778b390556e9a68af5e489e14616fe9
BLAKE2b-256 55c8ed1dda1d387b82f95913fd0c5b43415fe69f7f4166652acfc9d26a7914bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page