Skip to main content
# opyum

[![version](https://img.shields.io/pypi/v/opyum.svg)](http://pypi.python.org/pypi/opyum)
[![downloads](https://img.shields.io/pypi/dw/opyum.svg)](http://pypi.python.org/pypi/opyum)
[![license](https://img.shields.io/pypi/l/opyum.svg)](http://pypi.python.org/pypi/opyum)
[![status](https://img.shields.io/pypi/status/opyum.svg)](http://pypi.python.org/pypi/opyum)
[![pyversions](https://img.shields.io/pypi/pyversions/opyum.svg)](http://pypi.python.org/pypi/opyum)


## Description

**Optimizing Python applications without mutilation code.**

Use the automatic modification of AST for code optimization, which is transparent to the user and requires the addition of only a few lines.


## Usage

**Decorator**:

```python
from opyum import optimize

@optimize
def function_for_optimize():
...
```

**Import-hook**:

```python
import opyum
opyum.activate()

# other imports
```

**"With" syntax:**

```python
import opyum

with opyum.activate:
# other imports
```

**Command-line mode:**

Show optimized source:

$ opyum show myfile.py

Diff between original source and optimized source:

$ opyum diff myfile.py

Console diff (with "-c" or "--console" option):

![console diff example](https://raw.githubusercontent.com/Amper/opyum/master/example/screen1.png)

Custom app diff (with "--app" option):

![app diff example](https://raw.githubusercontent.com/Amper/opyum/master/example/screen2.png)

By default, html diff (without options):

![app diff example](https://raw.githubusercontent.com/Amper/opyum/master/example/screen3.png)


## List of optimizations

####Constant folding

Before:

```python
x = 7 * 24 * 60 * 60
y = [i ** 2 for i in range(10) if i % 2 == 0]
z = sum(range(1000))
```

After:

```python
x = 604800
y = [0, 4, 16, 36, 64]
z = 499500
```

####"'Power' to 'multiplication'" optimization

Before:

```python
x1 = a ** (-2)
x2 = a ** (-1)
x3 = a ** ( 0)
x4 = a ** ( 1)
x5 = a ** ( 2)
```

After:

```python
x1 = 1 / (a * a)
x2 = 1 / a
x3 = 1
x4 = a
x5 = a * a
```

####"'Yield' to 'yield from'" optimization

Before:

```python
for x in some_expression:
yield x
```

After

```python
yield from some_expression
```

####Builtin constant propagation

Before:

```python
from math import pi
def circumference(r):
return 2 * pi * r
```

After:

```python
from math import pi
def circumference(r):
return 2 * 3.141592653589793 * r
```

####Custom constant propagation

Before:

```python
C_PI = 3.141592653589793

def circumference(r):
return 2 * C_PI * r
```

After:

```python
C_PI = 3.141592653589793

def circumference(r):
return 2 * 3.141592653589793 * r
```

####Dead code elimination

Before:

```python
def do_something():
return 1
print('returning 1')

if condition1:
pass
elif condition2:
do_something()
else:
pass
```

After:

```python
def do_something():
return 1

if not condition1 and condition2:
do_something()
```


## Installation

Installation is simple with pip:

$ pip install opyum

or with setuptools:

$ easy_install opyum


## Documentation

[opyum.readthedocs.org](http://opyum.readthedocs.org/)

[opyum.rtfd.org](http://opyum.rtfd.org/)

Metadata

Release files for opyum 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opyum 0.2
File Size Uploaded Provenance Actions
opyum-0.2.tar.gz 20.5 kB Without provenance Details for opyum-0.2.tar.gz

Release files / opyum-0.2.tar.gz

Download URL opyum-0.2.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
706b3c38f68a6ff275e76f76c1fb7c2c25c132766c49d8216880b6261ed95a0d
BLAKE2b-256 checksum
How to use checksums
76a1e3efd5bb4d3cc7c0eaff309c62b8a5dc88de68b1fb5de37f305c02a04892
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for opyum 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page