Posts tagged: python

All posts with the tag "python"

312 posts latest post 2026-05-06
Publishing rhythm
Jan 2026 | 3 posts

005

** setup is _

1 min

pre-commit is awesome

I recently discovered the ✨ awesomeness that is pre-commit. I steered away from it for so long because it seemed like a big daunting thing to set up, but really it’s easy. It will automatically run checks for you. In some cases, it will even automatically fix them for you. Out of the box, it will do things like automatically trim extra whitespace, fix file endings, and ensure file sizes are not too large for git [1]. I recently discovered the ✨ awesomeness that is pre-commit. I steered away from it for so long because it seemed like a big daunting thing to set up, but really it’s easy. It will automatically run checks for you. In some cases, it will even automatically fix them for you. Out of the box, it will do things like automatically trim extra whitespace, fix file endings, and ensure file sizes are not too large for git. Quickstart # [2] It comes with a sample-config that is pretty general purpose and use for just about any project in git. pip instal pre-commit pre-commit s...
4 min read ↺ 6

004

🔥 #kedrotips use find-kedro to assembly your pipelines

1 min

002

** 0.3.0 just launched with _ support 🎉

1 min

Kedro Static Viz 0.3.0 is out with Hooks Support

kedro-static-viz [1] is out with support for the newly released hooks feature. This means that you can have kedro-static-viz automatically deploy a full gatsby site before_pipeline_run keeping your visualization always up to date. Even though it is a static site there is no functionality lost. The only thing that’s missing is the flask server. With kedro-static-viz [1] you can deploy your visualization to a number of static hosting providers such as GitHub pages free of charge with wicked fast performance ⚡ It’s Fast # [2] Even though it’s built on gatsbyjs the full site builds in under 2s even on slower hardware. This is because the site is already pre-rendered and stripped of any excess. It’s zipped up right into the python package and is typically used with the cli, but now can be used with python, or as a hook as well. What is kedro-viz [3] 🤔 # [4] Kedro viz is a fantastic kedro plugin that allows you to visualize your data pipeline. Kedro allows you to quickly build produc...

Brainstorming Kedro Hooks

This post is a 🧠 branstorming work in progress. I will likely use it as a storage location/brain dump of hook ideas. What is Kedro 🤔 # [1] If you are completely unsure what kedro is be sure to check out my what is kedro [2] post after_catalog_created # [3] - filepath replacer - bucket replacer before_pipeline_run # [4] - preflight - check that data exists - run kedro_static_viz - run mypy - run interrogate - run flake8 after_pipeline_run # [5] - Great Expectations - send email - send slack before_node_run # [6] after_node_run # [7] - Great Expectations - save stats/meta data - Execution Order # [8] hooks are executed in reverse order of the hooks list. hooks with tryfirst will be moved to the end of the list hooks with trylast will be moved to the end of the list - after_catalog_created - before_pipeline_run - args - run_params = run_params = {‘run_id’: ‘2020-05-23T15.24.23.958Z’, ‘project_path’: ‘/mnt/c/temp/kedro0160’, ’env’: ’local’, ‘kedro_version’: ‘...

Create Custom Kedro Dataset

Kedro provides an efficient way to build out data catalogs with their yaml api. It allows you to be very declaritive about loading and saving your data. For the most part you just need to tell Kedro what connector to use and its filepath. When running Kedro takes care of all of the read/write, you just reference the catalog key. But what is happening behind the scenes # [1] Under the hood there is an AbstractDataSet that each connector inherits from. It sets up a lot of the behind the scenes structure for us so that we dont have to. For the most part kedro has connectors for about anything that you want to load, csv, parquet, sql, json, from about anywhere, http, s3, localfile system are just some of the examples. Here is a DataSet implementation from their docs. Here you can see the barebones example straight from the docs. Parameters from the yaml catalog will get passed in from pathlib import Path import pandas as pd from kedro.io import AbstractDataSet class MyOwnDataSet(...

Interrogate is a pretty awesome, brand new, cli for Python packages

As usual while listening to python bytes 181 [1] I heard of a tool that I had to try out right away! This thing is 🔥 hot off the press folks, we’re talking the first release only 3 weeks ago. Its something that the python community needed years ago, and it belongs in your CI today. I had tried several tools that tried to do docstring coverage in the past but they were a bit cumbersome and were quickly forgotten about. Not interrogate, its dead simple! Nothing I have tried has come close to being this good Interrogate # [2] It runs documentation coverage for your python project. It allows you to set the minimum amount of docstring coverage for your project and has some great setup instructions right in the readme. Install it # [3] Interrogate is on pypi so it is super simple to install with pip pip install interrogate run it # [4] This is the best part, its super easy to run right from the command line! Just call it, and give it a path to run. interrogate -v <path> 😲 I hav...
2 min read

creating the kedro-preflight hook

Kedro Hooks Intro - kedro hooks are an exciting upcoming feature of kedro 0.16.0. They allow you to hook into catalog_created,pipeline_run, and node_run(nouns). With a before, or after (adjective). This really reminds me of reacts lifecycle hooks, that let you hook into various state of react web components. This is going to make kedro so extendable by the community. I am super pumped to see what the community is able to do with this ability. kedro hooks are an exciting upcoming feature of kedro 0.16.0. They allow you to hook into catalog_created,pipeline_run, and node_run(nouns). With a before, or after (adjective). This really reminds me of reacts lifecycle hooks, that let you hook into various state of react web components. This is going to make kedro so extendable by the community. I am super pumped to see what the community is able to do with this ability. What is Kedro [1] If you are completely unsure what kedro is be sure to check out my what is kedro post Docs # [2] a w...

📝 Kedro Preflight Notes

This is a very rough idea for a kedro package to prevent time lost to get partway through a pipeline run only to realize that you dont have access to data or resources. Must Haves # [1] - check that inputs exist or are of a type to skip (sql) Good to haves - check that all input and output databases are accessible with good credentials - check for s3 bucket access - check for spark install Implementation # [2] @hook_spec def before_pipeline_run(run_params, pipeline, catalog): run params # [3] { "run_id": str "project_path": str, "env": str, "kedro_version": str, "tags": Optional[List[str]], "from_nodes": Optional[List[str]], "to_nodes": Optional[List[str]], "node_names": Optional[List[str]], "from_inputs": Optional[List[str]], "load_versions": Optional[List[str]], "pipeline_name": str, "extra_params": Optional[Dict[str, Any]] } References: [1]: #must-haves [2]: #implementation [3]: #run-params

📢 Announcing find-kedro

find-kedro is a small library to enhance your kedro experience. It looks through your modules to find kedro pipelines, nodes, and iterables (lists, sets, tuples) of nodes. It then assembles them into a dictionary of pipelines, each module will create a separate pipeline, and __default__ being a combination of all pipelines. This format is compatible with the kedro _create_pipelines format. [1] [2] [3] [4] # [5] kedro is a ✨ fantastic project that allows for super-fast prototyping of data pipelines, while yielding production-ready pipelines. find-kedro enhances this experience by adding a pytest like node/pipeline discovery eliminating the need to bubble up pipelines through modules. When working on larger pipeline projects, it is advisable to break your project down into different sub-modules which requires knowledge of building python libraries, and knowing how to import each module correctly. While this is not too difficult, in some cases, it can trip up even the most se...

TIL: Bind arguments to dynamically generated lambdas in python

This past week I had a really weird bug in my kedro [1] pipeline. For some reason data running through my pipeline was coming out completely made no sense, but if I manually request raw data outside of the pipeline it matched expectations. NOTE While this story is about a kedro pipeline, it can be applied anywhere closures are put into an iterable. [2] # [3] After a few days of looking at it off and on, I pinpointed that it was all the way down in the raw layer. Right as data is coming off of the database. For this I already had existing sql files stored and a read_sql function to get the data so I opted to just set up the pipeline to utilize the existing code as much as possible, leaning on the kedro [1] framework a bit less. I have dynamically created lists of pipeline nodes many times in the past, but typically I take data from kedro [1] input and use it in the lambda. I prefer the simplicity of using lambdas over functools.partial. It typically looks something like this. #...
2 min read

python-deepwatch

Is it possible to deep watch a single python function for changes? Shallow Watch # [1] keeping track of a python functions hash is quite simple. There is a__hash__ method attached to every python function. Calling it will return a hash of the function. If the function changes the hash will change. [ins] In [1]: def test(): ...: return "hello" [ins] In [2]: test.__hash__() Out[2]: 8760526380347 [ins] In [3]: test.__hash__() Out[3]: 8760526380347 [ins] In [4]: def test(): ...: return "hello world" [ins] In [5]: test.__hash__() Out[5]: 8760525617988 [ins] In [6]: def test(): ...: return "hello" [ins] In [7]: test.__hash__() Out[7]: 8760526380491 Using hashlib provides a consistent hash. import inspect import hashlib def test(): return "hello" [ins] In [17]: m.update(inspect.getsource(test).encode()) [ins] In [18]: m Out[18]: <sha256 HASH object @ 0x7f7b7b70fde0> [ins] In [19]: m.hexdigest() Out[19]: '1f2ff4c69eb69b545469686edd6f849136e104cd535785891586d90620328757' [i...
1 min read

Four Github Actions for Python

If you are developing python packages and using GitHub here are four actions that you can use today to automate your release workflow. Since python tools generally have such a simple cli I have opted to use the cli for most of these, that way I know exactly what is happening and have more control over it if I need. h2 img { width: 100%; box-shadow: .5rem .5rem 3rem #141F2D, -.5rem -.5rem 3rem rgba(255,255,255,.1);} img{ max-width: 100% !important;} If you are developing python packages and using GitHub here are four actions that you can use today to automate your release workflow. Since python tools generally have such a simple cli I have opted to use the cli for most of these, that way I know exactly what is happening and have more control over it if I need. - Lint - Test - Package - Upload to PyPi Lint With flake8 # [1] flake8 is pythons quintessential linting tool to ensure that your code is up to the standards that you have set for the project, and to help prevent hidden...

Variables names don't need their type

So often I see a variables type() inside of its name and it hurts me a little inside. Tell me I’m right or prove me wrong below. Examples # [1] Pandas DataFrames are probably the worst offender that I see # bad sales_df = get_sales() # good sales = get_sales() Sometimes vanilla structures too! # bad items_list = ['sneakers', 'pencils', 'paper', ] # good items = ['sneakers', 'pencils', 'paper', ] Edge Cases? # [2] It’s so common when you need to get inside a data structure in a special way that itsn’t provided by the library…. I am not exactly sure of a good way around it. # bad ?? sales = get_sales() sales_dict = sales.to_dict() # good 🤷‍♀️ Containers are plural # [3] Always name your containers plural, so that naming while iterating is simple. prices = {} items = ['sneakers', 'pencils', 'paper', ] for item in items: prices[item] = get_price(item) Before I start fights 🥊 in code review, am I inline here or just being pedantic? References: [1]: #examples [2]: #edge-cases...

Create New Kedro Project

This is a quickstart to getting a new kedro [1] pipeline up and running. After this article you should be able to understand how to get started with kedro [1]. You can learn more about this Hello World Example [2] in the docs [2] 🧹 Install Kedro [1] 🛢 Create the Example Pipeline 💨 Run the example 📉 Show the pipeline visualization Create a Virtual Environment [3] # [4] I use conda to control my virtual environments and will create a new environment called kedro_iris with the following command. note the latest compatible version of python is 3.7. EDIT: as of kedro 0.16.0 kedro supports up to 3.8 conda create -n kedro_iris python=3.8 -y [5] Options Activate your conda environment # [6] I try to keep my base environment as clean as possible. I have ran into too many issues installing things in the base environment. Almost always its some dependency that starts causing issues making it even harder to realize where its coming from as I never even installed it in base. source...

What is YOUR Advice for New Data Scientists

- Learn the business - Learn Git [1] - Your code does not need to be amazing - Keep Learning Learn Git # [2] You dont have to start out as a git wizard with the cleanest possible commit history. At first dont let yourself get too wrapped up in it, the most important part is that you make commits. You will find needs for more advanced stuff later. git add . git commit -m "FEAT added new function to calculate revenue by product family" git push Get comfortable with this, then learn how to branch, rebase, stash, etc… Your code does not need to be amazing # [3] Get the job done. Keep it in small bite size pieces. Make readable function definitions and variable names. You will thank yourself for naming things well later. Readability counts more than performance in most cases of data science. If it gets the job done try not to over worry about things like performance. A few extra seconds to clean a dataset or build a model is not worth hours of your time. As you go you will have c...

What is Kedro

What is Kedro [1] This is my original what-is-kedro article. There is a brand new one --- Kedro is an open source data pipeline framework. It provides guardrails to set your project up right from the start without needing to know deeply how to setup your own python library for data pipelining. It includes really great ways to manipulate catalogs and pipelines. This article will cover the 10K view of kedro, future articles will dive deper into each one. kedro [2] is an open-source data pipeline framework. It provides guardrails to set your project up right from the start without needing to know deeply how to set up your own python library for data pipelining. It includes great ways to manipulate catalogs and pipelines. This article will cover the 10K view of kedro [2], future articles will dive deeper into each one. Libraries # [3] Currently, kedro [2] is broken down into 3 different libraries. 💎 kedro [2] 📉 kedro-viz [4] 🏗 kedro-docker [5] kedro [2] # [6] [7] kedro [2] ...