Skip to main content

Outsourcer

A micro library for generating Python source code.

Installation

pip install outsourcer

Outsourcer requires Python 3.6 or later.

Why does this exist?

Sometimes you have to generate some Python code, and sometimes it's a bit too complicated for using string templates. This is a small library you can use in those cases.

Example

Hello, World

>>> from outsourcer import sym
>>> sym.print('hello, world')
print('hello, world')

This example uses sym to create a code fragment.

Control Flow

Here's a longer example:

>>> from outsourcer import CodeBuilder, sym
>>> b = CodeBuilder()
>>> item = sym.item
>>> with b.FOR(item, in_=sym.some_collection):
...     with b.IF(item % 2 == 0):
...         b += sym.print('even')
...     with b.ELSE():
...         b += sym.skipped.append(item)
...
>>> print(b.source_code())
for item in some_collection:
    if ((item % 2) == 0):
        print('even')
    else:
        skipped.append(item)

Metadata

Release files for outsourcer 0.0.1

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

Source distribution (sdist)

Source distribution for outsourcer 0.0.1
File Size Uploaded Provenance
outsourcer-0.0.1.tar.gz 4.3 kB Without provenance Details

Release files / outsourcer-0.0.1.tar.gz

Download URL outsourcer-0.0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5764b5e1c494920cc399d263256d84545259341b978bc8c40c7e56befd3cac89
BLAKE2b-256 checksum
How to use checksums
d196e4466a67d878b6e3fafc55fc04405b463dea2e72676e9587d080949eb7c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

Security for outsourcer 0.0.1

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.0.1 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