Home / Companies / Pybites / Blog / August 2021

August 2021 Summaries

8 posts from Pybites

Filter
Month: Year:
Post Summaries Back to Blog
Separating configuration from code is essential to maintainability and security, and the article discusses three Python libraries that facilitate this process: python-dotenv, python-decouple, and dj-database-url. Python-dotenv allows developers to store environment variables in a .env file and access them using simple code without altering the environment, thereby preventing sensitive information from being committed to version control systems like Git. Python-decouple offers similar functionality but with the added convenience of casting and default values, especially useful in Django applications for managing configuration variables. Lastly, dj-database-url helps manage database connection settings by parsing a database URL into a Django-compatible configuration dictionary, simplifying the process of setting up database connections in web applications. The article underscores the importance of adhering to The Twelve-Factor App principle of separating config from code and provides practical code snippets and tips to aid developers in implementing these practices effectively.
Aug 31, 2021 701 words in the original blog post.
The article provides a comprehensive guide on how to package Python code as a Command Line Interface (CLI) application using PyPA's setuptools without external dependencies, offering insights into the evolution of Python packaging tools. It details the transition from the traditional setup.py script to the configuration-based setup.cfg and the emerging pyproject.toml format, highlighting their roles in specifying project metadata and CLI entry points. The article explains the process of creating Python distribution builds using setuptools and the PyPA build system, including generating wheel files for efficient deployment. It also addresses the importance of structuring a Python CLI project, discusses alternative packaging tools like Poetry and Flit, and mentions utilities for creating standalone executable files, emphasizing the benefits and limitations of each approach in different deployment contexts.
Aug 30, 2021 3,190 words in the original blog post.
This article is the second part of a series on Python's type annotation system, focusing on practical examples to help newcomers enhance code quality and readability through type hints. It builds on the introductory concepts of static and dynamic typing and demonstrates the advantages of using type hints, such as improved auto-completion and clearer return types in code editors like Visual Studio Code with the Pylance language server. The article explains the use of basic and complex data types from the typing module, such as typing.List and typing.Iterable, and emphasizes the importance of specifying element types within collections to avoid defaulting to Any or Unknown. It highlights the flexibility of Python 3.9 in allowing the use of built-in data types directly as type hints, contrasting it with earlier versions that require imports from the typing module. The article concludes with a brief mention of resources and future articles on more advanced type hint applications.
Aug 27, 2021 1,324 words in the original blog post.
Applying the hedgehog concept can enhance both personal and professional development by focusing on projects that align with one's passion, existing skills, and economic potential. This approach is exemplified by the author's experience as a support engineer, where he combined his passion for automation, coding skills, and server diagnostics to create tools that advanced his career. Similarly, a client applied her domain knowledge and coding skills to develop an image labeling pipeline with future product potential. The post encourages using Python creatively to achieve meaningful work and career growth, emphasizing the importance of building projects that integrate personal interests and expertise. It also offers support through a Slack community and free assessment calls to help individuals brainstorm and refine their project ideas.
Aug 20, 2021 387 words in the original blog post.
GitHub Actions is a powerful tool for automating workflows within a GitHub repository, helping developers catch errors early and streamline processes. While it is ideal for developers to address issues locally before code is pushed, GitHub Actions provides a centralized way to run tests and quality checks automatically, reducing time and resource expenditures. This service enables various automated tasks triggered by certain events, such as deploying code to a cloud provider, pushing packages to PyPI, publishing Docker images, and more. Setting up GitHub Actions is straightforward; it involves creating a specific folder structure and adding workflow YAML files. The article concludes by offering examples of workflow files from open-source repositories and provides further resources for learning more about GitHub Actions.
Aug 13, 2021 314 words in the original blog post.
The article introduces the concept of type hints in Python, advocating for their use by explaining how they can make code more bug-free, accessible, and maintainable. It highlights the difference between static and dynamic typing, emphasizing Python's nature as a dynamically typed language that only checks types at runtime, potentially leading to hidden errors. Through type hints, which were introduced with PEP 484, Python code can benefit from static type checking without enforcing types, as they act as suggestions rather than strict rules. The article provides an example of a function with and without type hints to demonstrate the clarity and intention type hints bring to code, making it easier for developers to understand parameter types and expected function behavior. Although type hints don't affect runtime behavior, they can prevent bugs by making the programmer's intentions explicit, aligning with the Zen of Python's principle that "Explicit is better than implicit." The article encourages developers, especially newcomers, to start using type hints to improve their Python programming practices.
Aug 12, 2021 1,757 words in the original blog post.
A "brag doc" is a powerful motivational tool used to enhance confidence by recording personal achievements and milestones, both big and small. It serves as a personal document where individuals list their accomplishments over time, helping to combat self-doubt and negativity by reminding them of their successes. This technique aims to provide inspiration and a confidence boost during times of demotivation, encouraging individuals to include any achievement they perceive as valuable or a win. The practice is highly personalized, ensuring its effectiveness in uplifting one's mindset, and is used alongside accountability measures for optimal results.
Aug 05, 2021 366 words in the original blog post.
The Twitter discussion initiated by Bob Belderbos led to a compilation of insightful use cases for Python decorators, showcasing their versatility and power in programming. The five highlighted applications include de-duplicating code, which simplifies functions by abstracting repeated logic; protecting against bad inputs using the pydantic module's validator decorator; enhancing testing processes with pytest's fixtures and marks; improving logging practices with the time_taken decorator from the memo project; and managing authentication in web frameworks such as Flask and Django. Additionally, the text mentions the use of standard library decorators like @property and @classmethod for attribute access and creating alternative class constructors, respectively. The article encourages programmers to explore and implement these patterns in their work, offering resources for further learning through a dedicated Decorators Learning Path.
Aug 03, 2021 411 words in the original blog post.