After months of work, I'm thrilled to announce the release of the new edition of "Mastering Python Design Patterns"!
What's new?
This edition dives deep into creational, structural, behavioral, and architectural patterns, plus it introduces concurrency, asynchronous, and performance patterns.
What youβll learn:
π Master key design principles and SOLID concepts
π Implement Gang of Four (GoF) patterns in Python
π Use architectural patterns to build robust systems
π Optimize code with concurrency and performance patterns
π Scale applications with distributed systems patterns
π Ensure reliability with testing patterns
π Build modular, decoupled systems and manage dependencies efficiently
Stay tuned for more updates! πβ¨ #Python #Coding #DesignPatterns
Shipped the first version of the UX for my LLM β Structured Data Connector. Next work involves advanced ways of providing the data schema input (JSON, CSV).
Day 9 slice shipped: Minimal UX with Gradio β
To test:
- Install/update dependencies in your virtual environment.
- Run: python https://t.co/4eCDgiea4o
- Visit http://127.0.0.1:7860
Currently, you can generate the result by providing the prompt and the list of columns.
Repo: https://t.co/s718xw9DoI
Branch: ux-with-gradio
Next up: Ability to specify the schema of the data returned by providing a JSON string or a "template" CSV. Do you see another option?
Day 9 slice shipped: Minimal UX with Gradio β
To test:
- Install/update dependencies in your virtual environment.
- Run: python https://t.co/4eCDgiea4o
- Visit http://127.0.0.1:7860
Currently, you can generate the result by providing the prompt and the list of columns.
Repo: https://t.co/s718xw9DoI
Branch: ux-with-gradio
Next up: Ability to specify the schema of the data returned by providing a JSON string or a "template" CSV. Do you see another option?
As a dev / builder, I needed a fresh approach to things.
I started a build-in-public sprint: 6 ideas tested β picked the "LLM β Structured Data Connector" idea today.
Iβll post daily progress + a Day-14 demo.
Iβm sharing raw notes inside my SkoolβDM if you want in.
Day 8 slice shipped: CLI for prompt and other input β file out β
It is possible to test with:
python https://t.co/fAO5Ba8cKv "Produce the list of currencies with the countries" --col "currency_name" --col "ticker" --col "country" --rows 20 --output "out/currencies.csv"
It does some validation of the data after parsing the response, and then writes the file.
Repo: https://t.co/s718xw9DoI
Branch: cli-with-typer
My current thinking is generating a CSV, and then make it possible to move the data from the CSV to other databases / formats / storages, using existing techniques/tools. What do you think?
Shipped the CLI slice for my LLM β Structured Data Connector.
Currently, you can define the schema with --col.
Note: The --col option might get adjusted. I may also add a preview of the data before writing.
Next: Small UX (going to try Gradio first).
Would you target the other output stores/formats (SQL, JSON) by using custom code in the package directly or would you delegate that to standard pipeline/ELT/ETL tools?
Day 8 slice shipped: CLI for prompt and other input β file out β
It is possible to test with:
python https://t.co/fAO5Ba8cKv "Produce the list of currencies with the countries" --col "currency_name" --col "ticker" --col "country" --rows 20 --output "out/currencies.csv"
It does some validation of the data after parsing the response, and then writes the file.
Repo: https://t.co/s718xw9DoI
Branch: cli-with-typer
My current thinking is generating a CSV, and then make it possible to move the data from the CSV to other databases / formats / storages, using existing techniques/tools. What do you think?
Been out of this account for more than a year, spending time elsewhere. Life happens and there is so much to do in this world π
I am back with improved skills and new ideas. Let's reignite/continue the conversations.
π Python Tip of the Day: Utilizing Pythonβs β-mβ Option for Module Execution
Python's `-m` option is a versatile tool that allows you to run library modules as scripts. This can be incredibly useful for executing modules that contain test code or need to perform initialization tasks. It runs the source file for a module located in the Python module search path.
One common use of the `-m` option: Launch Python's built-in HTTP server, which can serve files from the current directory over HTTP. This is very useful for quick tests, sharing files, or local development work.
```
# Serve files from the current directory at http://localhost:8000/
python -m http.server
```
Another popular usage: Run the `pip` installer to ensure that you are using the module corresponding to the Python interpreter you're currently using:
```
# Upgrade the pip installer using the -m option
python -m pip install --upgrade pip
```
Benefits:
1οΈβ£ Flexibility: Offers a straightforward way to execute Python modules from the command line, providing a flexible approach for various Python tasks.
2οΈβ£ Utility: Great for utility tasks like running a web server, profiling code, testing, or package management, all without additional scripts.
3οΈβ£ Safe imports: Ensures that the module is imported correctly, potentially avoiding shadowing issues that can occur when a module and a script have the same name.
9οΈβ£ Boosting efficiency with the `cached_property` decorator
The `cached_property` decorator transforms a method into a property whose value is cached after the first access. So the method will only be executed once, and subsequent accesses retrieve the cached result, saving computation time and resources.
Benefits:
1. Reduced load times: For web applications and data-heavy applications, this tool can lead to faster response times by caching frequently requested but rarely changed data.
2. Ease of maintenance: The caching logic is abstracted away by the decorator, making the code cleaner and easier to maintain.
3. Consistency: The cached value remains consistent between accesses, which is crucial for ensuring that repeated requests for the property return the same result, assuming no changes in the underlying data.
Here are 9 useful Python decorators, from the standard library, that can enhance your productivity and help improve your codebase. πβ¨π
1οΈβ£ Using the `classmethod` decorator for state management
https://t.co/bEKY6av80j
π Python Tip of the Day: Utilizing the classmethod Decorator for State Management
In object-oriented programming with Python, the `classmethod` decorator allows you to define methods bound to the class rather than its instances. This capability is crucial for managing state or behavior that is common to all instances of the class, rather than individual objects.
When to Use It?
1οΈβ£ Managing shared state: Use it to manage data that is shared among all instances of a class. For example, keeping a count of all instances ever created.
2οΈβ£ Factory methods: Excellent for defining alternative constructors. You can create class methods that return instances of the class, configured in different ways.
3οΈβ£ Accessing class attributes: They provide a way to access or modify class state that applies across all instances, like modifying a configuration setting that affects all instances.
π Python Tip of the Day: Simplifying Resource Management with `contextlib.contextmanager` Decorator
Python's `contextlib.contextmanager` decorator is a handy tool for creating simple and readable context managers without the need for a class that implements `__enter__` and `__exit__` methods. This decorator is ideal for managing resources like files, network connections, or locks that need to be set up and cleaned up reliably, no matter what happens during their use.
Example use case: Create a temporary file and ensure it gets deleted after use.
Benefits:
1οΈβ£ Reduced boilerplate: Eliminates the need to write an entire class with `__enter__` and `__exit__` methods, reducing boilerplate and overhead.
2οΈβ£ Exception handling: Automatically handles exceptions within the `with` block, ensuring that the cleanup code is executed.
3οΈβ£ Flexibility in resource handling: Allows more flexible handling of how resources are passed to the block enclosed by the `with` statement.