Module Documentation

builder

Builder reads and executes tasks and lists of tasks.

laforge.builder.show_env(path)[source]

Show the calculated generic section environment

class laforge.builder.Verb[source]

An enumeration.

class laforge.builder.Target[source]

An enumeration.

class laforge.builder.FileCall(method, kwargs)
property kwargs

Alias for field number 1

property method

Alias for field number 0

exception laforge.builder.TaskConstructionError[source]
exception laforge.builder.TaskExecutionError[source]
class laforge.builder.TaskList(from_string, location='.')[source]

Todo

Implement cache_results=False

load_section_config(section='DEFAULT')[source]

Put together config from env, TaskList config, section config

execute()[source]

Execute each task in the list.

Todo

Restore quiet?

dry_run()[source]

List each task in the list.

class laforge.builder.BaseTask(*, identifier, verb, target, content, config)[source]

Create a task to (verb) (something)

Todo

if “:” in self.content:

previous_result_key, actual_path_content = self.content.split(“:”)

property path

For handlers where dir[verb] + content = path

class laforge.builder.FileReader(*, identifier, verb, target, content, config)[source]
class laforge.builder.InternalPythonExecutor(*, identifier, verb, target, content, config)[source]

Execute (without importing) Python script by path

Allows script adjustment via setting the run name: __main__ = 'laforge'

..todo

Allow implict/explicit return of results.
class laforge.builder.Echoer(*, identifier, verb, target, content, config)[source]
class laforge.builder.SQLQueryReader(*, identifier, verb, target, content, config)[source]
class laforge.builder.SQLExecutor(*, identifier, verb, target, content, config)[source]
class laforge.builder.SQLReaderWriter(*, identifier, verb, target, content, config)[source]
class laforge.builder.FileWriter(*, identifier, verb, target, content, config)[source]

Handles all tasks writing to file.

class laforge.builder.ExistenceChecker(*, identifier, verb, target, content, config)[source]
laforge.builder.load_env(path)[source]

Get .env values without dotenv’s default to silently pull package dir

command

Command-line interface for laforge.

distros

exception laforge.distros.SQLDistroNotFound[source]
class laforge.distros.Distro(_)[source]

Base class for SQL Distros

..note:: http://troels.arvin.dk/db/rdbms/

class laforge.distros.MySQL(_)[source]
class laforge.distros.PostgresQL(_)[source]
class laforge.distros.MSSQL(_)[source]
static add_fast_executemany(engine: sqlalchemy.engine.base.Engine)[source]

Dramatically improve pyodbc upload performance

Theoretically, just “fast_executemany”: “True” should be sufficient in newer versions of the driver.

Note

Improved 1m row upload from over 7 minutes to less than 1 under pyodbc==4.0.26, SQLAlchemy==1.3.1, pandas==0.24.2.

class laforge.distros.SQLite(_)[source]
determine_dtypes(df)[source]

SQlite does not make gradations in integers or text, so don’t try.

laforge.distros.round_up(n, nearest=1)[source]

Round up n to the nearest nearest.

Parameters
  • n

  • nearest – (Default value = 1)

sql

SQL utilities for mid-level interaction. Inspired by pathlib; powered by SQLALchemy.

Note

Supported: MSSQL, MariaDB/MySQL, PostgreSQL, SQLite. Supportable: Firebird, Oracle, Sybase.

exception laforge.sql.SQLTableNotFound[source]
exception laforge.sql.SQLChannelNotFound[source]
exception laforge.sql.SQLIdentifierProblem[source]
class laforge.sql.Channel(distro, *, server=None, database=None, schema=None, **engine_kwargs)[source]

Abstraction from Engine, other static details.

execute_statement(statement, fetch=False)[source]

Execute SQL (core method)

Todo

De-messify

laforge.sql.execute(statement, fetch=False, channel=None)[source]

Convenience method, autofetches Channel if possible

class laforge.sql.Script(query, channel=None)[source]

SQL query string, parsable by ‘go’ separation and execute()able.

execute(statements=None)[source]

Execute itsel(f|ves)

to_table()[source]

Executes all and tries to return a DataFrame for the result of the final query.

This is one of two ways that laforge retrieves tables.

Warning

This is limited by the capacity of Pandas to retrieve only the final result. For Microsoft SQL Server, if a lengthy set of queries is desired, the most reliable approach appears to be a single final query after a ‘go’ as a batch gterminator.

Warning

This will rename columns that do not conform to naming standards.

class laforge.sql.Table(name, channel=None, **kwargs)[source]

Represents a SQL table, featuring methods to read/write DataFrames.

Todo

Factor out to superclass to allow views

write(df, if_exists='replace')[source]

From DataFrame, create a new table and fill it with values

read()[source]

Return the full table as a DataFrame

drop(ignore_existence=False)[source]

Delete the table within SQL

class laforge.sql.Scalar(prox)[source]

Little helper to produce clearly typed single (upper left) ResultProxy result.

class laforge.sql.Identifier(user_input, extra=None)[source]

Single standardized variable/database/schema/table/column/anything identifier.

Todo

class InvalidIdentifierError relay_id_problem(identifier, action, reason=None, replacement=None)

tech

laforge.tech.make_first_upper(s)[source]

Uppercase the first letter of s, leaving the rest alone.

toolbox

Handful of utility functions

Note

These intentionally only depend on builtins.

Note

Some copyright information within this file is identified per-block below.

laforge.toolbox.flatten(foo)[source]

Take any set of nests in an iterator and reduce it into one generator.

‘Nests’ include any iterable except strings.

Parameters

foo

Note

flatten() was authored by Amber Yust at https://stackoverflow.com/a/5286571. This function is not claimed under the laforge license.