Skip to main content

PolyglotPiranha

PolyglotPiranha is a lightweight code transformation toolset for automating large scale changes. At Uber, it is mostly used to clean up stale feature flags.

We only support languages that are used at Uber. We likely won't be able to add new languages in this repo. There are a number of forks (see https://github.com/uber/piranha/forks for a full list) that may provide additional features.

Installation

To install Polyglot Piranha, you can use it as a Python library or as a command-line tool.

Python API

To install the Python API, run the following command:

pip install polyglot-piranha

Command-line Interface

To install the command-line interface, follow these steps:

  1. Install Rust
  2. Clone the repository: git clone https://github.com/uber/piranha.git
  3. Navigate to the cloned directory: cd piranha
  4. Build the project: cargo build --release (or cargo build --release --no-default-features for macOS)
  5. The binary will be generated under target/release

Example Usage

from polyglot_piranha import execute_piranha, PiranhaArguments, Rule, RuleGraph, OutgoingEdges

# Original code snippet
code = """
if (obj.isLocEnabled() || x > 0) {
    // do something
} else {
    // do something else!
}
"""

# Define the rule to replace the method call
r1 = Rule(
    name="replace_method",
    query="cs :[x].isLocEnabled()", # cs indicates we are using concrete syntax
    replace_node="*",
    replace="true",
    is_seed_rule=True
)

# Define the edges for the rule graph. 
# In this case, boolean_literal_cleanup is already defined for java [see src/cleanup_rules]
edge = OutgoingEdges("replace_method", to=["boolean_literal_cleanup"], scope="parent")

# Create Piranha arguments
piranha_arguments = PiranhaArguments(
    code_snippet=code,
    language="java",
    rule_graph=RuleGraph(rules=[r1], edges=[edge])
)

# Execute Piranha and print the transformed code
piranha_summary = execute_piranha(piranha_arguments)
print(piranha_summary[0].content)

Documentation

For more examples and explanations of the toolset, please check our demos and extended POLYGLOT_README.md file.

Feature Flags

Feature flags are commonly used to enable gradual rollout or experiment with new features. In a few cases, even after the purpose of the flag is accomplished, the code pertaining to the feature flag is not removed. We refer to such flags as stale flags. The presence of code pertaining to stale flags can have the following drawbacks:

  • Unnecessary code clutter increases the overall complexity w.r.t maintenance resulting in reduced developer productivity
  • The flags can interfere with other experimental flags (e.g., due to nesting under a flag that is always false)
  • Presence of unused code in the source as well as the binary
  • Stale flags can also cause bugs

PolyglotPiranha is a tool that can automatically refactor code related to stale flags. At a higher level, the input to the tool is the name of the flag and the expected behavior, after specifying a list of APIs related to flags in a properties file. Piranha will use these inputs to automatically refactor the code according to the expected behavior.

PolyglotPiranha (as of May 2022) is a common refactoring tool to support multiple languages and feature flag APIs. For legacy language-specific implementations please check following tag.

A few additional links on Piranha:

  • Research paper published at PLDI 2024 on PolyglotPiranha.
  • A technical report detailing our experiences with using Piranha at Uber.
  • A blogpost presenting more information on Piranha.
  • 6 minute video overview of Piranha.

Support

If you have any questions on how to use Piranha or find any bugs, please open a GitHub issue.

Piranha Development

Piranha uses several grammar repositories with custom patches to support the transformations. While these patches are being upstreamed, there may be discrepancies between the grammars in this repository and the upstream grammars. Therefore, we have built a custom tree-sitter playground that can be used to test the grammars and queries for easier development:

https://uber.github.io/piranha/tree-sitter-playground/

License

Piranha is licensed under the Apache 2.0 license. See the LICENSE file for more information.

Note

This is not an official Uber product, and provided as is.

Metadata

Release files for polyglot-piranha 0.4.9

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

Source distribution (sdist)

Source distribution for polyglot-piranha 0.4.9
File Size Uploaded Provenance
polyglot_piranha-0.4.9.tar.gz 134.7 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for polyglot-piranha 0.4.9
File
polyglot_piranha-0.4.9-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
polyglot_piranha-0.4.9-cp312-cp312-manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ ARM64 Details
polyglot_piranha-0.4.9-cp312-cp312-macosx_10_13_universal2.whl CPython 3.12 CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) Details
polyglot_piranha-0.4.9-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
polyglot_piranha-0.4.9-cp311-cp311-manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ ARM64 Details
polyglot_piranha-0.4.9-cp311-cp311-macosx_10_13_universal2.whl CPython 3.11 CPython 3.11 macOS 10.13+ universal2 (ARM64, x86-64) Details
polyglot_piranha-0.4.9-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details
polyglot_piranha-0.4.9-cp310-cp310-manylinux_2_28_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ ARM64 Details
polyglot_piranha-0.4.9-cp310-cp310-macosx_10_13_universal2.whl CPython 3.10 CPython 3.10 macOS 10.13+ universal2 (ARM64, x86-64) Details
polyglot_piranha-0.4.9-cp39-cp39-manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ x86-64 Details
polyglot_piranha-0.4.9-cp39-cp39-manylinux_2_28_aarch64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ ARM64 Details
polyglot_piranha-0.4.9-cp39-cp39-macosx_10_13_universal2.whl CPython 3.9 CPython 3.9 macOS 10.13+ universal2 (ARM64, x86-64) Details

Total release size: 62.7 MB

Release files / polyglot_piranha-0.4.9.tar.gz

Download URL polyglot_piranha-0.4.9.tar.gz
Size 134.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d25bd0afd5964bbe70046236635386999d3890d79e816283045984a89d0f57bf
BLAKE2b-256 checksum
How to use checksums
a9dea3174f2bf98a16f9502cf8a0661f606b5bf863c25b645e2d9cb00b22b6c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL polyglot_piranha-0.4.9-cp312-cp312-manylinux_2_28_x86_64.whl
Size 4.0 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
9c81d820ea5dfa1e71fe2dc73e4a34fd063a7eaf322561f2eacfd5913a1930f2
BLAKE2b-256 checksum
How to use checksums
7f7517b38130f411e07b4dfdb5feb1fa4630399a12c276f88c6b0d73bf90db23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp312-cp312-manylinux_2_28_aarch64.whl

Download URL polyglot_piranha-0.4.9-cp312-cp312-manylinux_2_28_aarch64.whl
Size 4.0 MB
Tags CPython 3.12 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
a03822f1346a3510d0e3bf02869054a268fd39979a92060d33a3aa9425236451
BLAKE2b-256 checksum
How to use checksums
d778d0ae8bef39fb673e9430cef288c76ab72d477b9ce677177831578512d34c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp312-cp312-macosx_10_13_universal2.whl

Download URL polyglot_piranha-0.4.9-cp312-cp312-macosx_10_13_universal2.whl
Size 7.7 MB
Tags CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
90c2904ba87840b9cf3733e0115ecb7b196aef0ee0247470a965c7d1d7221155
BLAKE2b-256 checksum
How to use checksums
ab003b4b09947381fc9dfcdaea06ddcf53dee5d1ccb2e8dddd7f114fd245b83c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL polyglot_piranha-0.4.9-cp311-cp311-manylinux_2_28_x86_64.whl
Size 4.0 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
a22d2d1d3e88aebb253982ea27b249611b672590b12f4c3561411433b12506fb
BLAKE2b-256 checksum
How to use checksums
874582a0dd4ace26c2c81f73edcd32f54ac41cf8901448f20635c7195ca58e8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp311-cp311-manylinux_2_28_aarch64.whl

Download URL polyglot_piranha-0.4.9-cp311-cp311-manylinux_2_28_aarch64.whl
Size 4.0 MB
Tags CPython 3.11 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
c03932c227849b5bb9a9afe888061301c96f1127af2dc1af7096aee9b552757e
BLAKE2b-256 checksum
How to use checksums
ba4d0030741ebb7922ec7be47f05c5ef634d6a98df18bcf64e5ba633e508d122
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp311-cp311-macosx_10_13_universal2.whl

Download URL polyglot_piranha-0.4.9-cp311-cp311-macosx_10_13_universal2.whl
Size 7.7 MB
Tags CPython 3.11 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
2b92d0b7c73fb7ebd2012cc7672c1f907e41b59faf2ceaaf7d6b26b52f593cec
BLAKE2b-256 checksum
How to use checksums
fa0c4c8323f1f081623e5a12ce5fe13c886fbcd407b358e4b3a0f9111ee47508
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL polyglot_piranha-0.4.9-cp310-cp310-manylinux_2_28_x86_64.whl
Size 4.0 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
08808542bbf578da6214ec4a90ebb9b1553d739a0f3baac5141e156551193670
BLAKE2b-256 checksum
How to use checksums
945305e5d16dd356672b62b533007198e19eab1e4df2f08cc3da1cc89d276af6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp310-cp310-manylinux_2_28_aarch64.whl

Download URL polyglot_piranha-0.4.9-cp310-cp310-manylinux_2_28_aarch64.whl
Size 4.0 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
b1a6d78cd0b474e7f8ab5f4f2663c41ac0f2b629ee207d583204e50c8506889c
BLAKE2b-256 checksum
How to use checksums
355b1bc699048d110553aa114342f7c5c64a72a466e219f6dc99eb506cea0eb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp310-cp310-macosx_10_13_universal2.whl

Download URL polyglot_piranha-0.4.9-cp310-cp310-macosx_10_13_universal2.whl
Size 7.7 MB
Tags CPython 3.10 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
309079700be88c17cc092a540c50e8c620071dfd438e1a04338a7f7c65be053b
BLAKE2b-256 checksum
How to use checksums
168dc8dd7f0e16cf487394ca34d03e527ced76654518d64da9aee6824689507b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp39-cp39-manylinux_2_28_x86_64.whl

Download URL polyglot_piranha-0.4.9-cp39-cp39-manylinux_2_28_x86_64.whl
Size 4.0 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b04feb520fac1aa4e5d67ddebeefe9fadd0ad515f6ba87996c1addd5460d54d5
BLAKE2b-256 checksum
How to use checksums
127faa7e19393b17ce2ee9417ef9b154eb8feafa229f5bce6e3fe0a2f0969877
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp39-cp39-manylinux_2_28_aarch64.whl

Download URL polyglot_piranha-0.4.9-cp39-cp39-manylinux_2_28_aarch64.whl
Size 4.0 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
1d1896b2373851ea8b782688266fe890d97e210f09b6fc82c9358d69b0318a3c
BLAKE2b-256 checksum
How to use checksums
94d06e9f6c2813894b0c69cb0b8cc4d33ff22ac761a43455c3a5393699e1707f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / polyglot_piranha-0.4.9-cp39-cp39-macosx_10_13_universal2.whl

Download URL polyglot_piranha-0.4.9-cp39-cp39-macosx_10_13_universal2.whl
Size 7.7 MB
Tags CPython 3.9 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
b5bc13db633bba88212f6f3c2cea040b991fa7427379a33877d2a4f480d7cba5
BLAKE2b-256 checksum
How to use checksums
7c4d3e8bf62dd62c568ba22fe9ca670fb13c5aeede73c03f88aa5fb88532b17d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for polyglot-piranha 0.4.9

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.

Release history Release notifications | RSS feed

This release

0.4.9 This release

13 release files 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