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)

Download files

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

Source Distribution

outsourcer-0.0.1.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file outsourcer-0.0.1.tar.gz.

File metadata

  • Download URL: outsourcer-0.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for outsourcer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5764b5e1c494920cc399d263256d84545259341b978bc8c40c7e56befd3cac89
MD5 4e51f094771b8c87c8be773630f29af1
BLAKE2b-256 d196e4466a67d878b6e3fafc55fc04405b463dea2e72676e9587d080949eb7c4

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 file

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