August 2020 Summaries
4 posts from Pybites
Filter
Month:
Year:
Post Summaries
Back to Blog
Deploying an open-source package to PyPI involves several important steps that enhance both functionality and usability. The process begins with creating a Python package, such as the PyBitesTips class, which utilizes methods like `__call__` for callable classes and `namedtuple` for data handling. Testing is streamlined by separating tests into a dedicated subdirectory and using mock data to simulate user interactions. The `setup.py` file plays a crucial role in making the project pip-installable by specifying dependencies and supported Python versions, and the `entry_points` feature enables the package to function as a command-line interface application. Uploading the package to PyPI involves creating distribution files, first testing on Test PyPI, and then publishing to the main PyPI server, with the use of tools like `setuptools`, `wheel`, and `twine` facilitating this process. The guide suggests maintaining a `.pypirc` file for easier authentication and highlights the evolving landscape of Python packaging, where alternatives like Poetry and `pyproject.toml` are gaining traction.
Aug 31, 2020
787 words in the original blog post.
The Zen of Python suggests that there should ideally be one clear way to accomplish tasks in programming, yet in practice, multiple solutions often exist, each with its own tradeoffs regarding efficiency, readability, and resource usage. This concept is evident in coding challenges, like those on PyBites, where diverse solutions emerge for the same problem. Evaluating different approaches helps programmers understand these tradeoffs and apply them effectively to meet specific requirements. An example illustrates that while a coding challenge aimed to teach a particular skill, the author found an alternative method by querying a calculator website to achieve the solution, demonstrating the value of recognizing when pre-existing solutions can be adapted. Additionally, the author learned to use built-in Python libraries like urllib and re due to the limitations imposed by the challenge, fostering creativity and problem-solving skills. Encouraging experimentation with different coding techniques and revisiting solved challenges can lead to new insights and learning opportunities.
Aug 21, 2020
556 words in the original blog post.
AWS Lambda is a serverless computing platform offered by Amazon Web Services that allows users to run code in response to events or HTTP requests. The article provides guidance on setting up a Lambda function using Python's standard library, including configuring an AWS Gateway API endpoint. It addresses the challenge of incorporating external libraries into Lambda, which typically requires creating a virtual environment, installing necessary packages, and packaging them into a zip file for upload. For some packages, such as pandas, the article suggests using Klayers to access pre-compiled packages compatible with AWS Lambda's environment. In cases where Klayers is insufficient, it recommends downloading wheel files or using docker-lambda to ensure compatibility. The text also encourages leveraging serverless technology like AWS Lambda for developing Software as a Service (SAAS) products, offering support for those interested in turning their ideas into business applications.
Aug 17, 2020
867 words in the original blog post.
Testing date and time-sensitive code in Python can be challenging, often requiring the mocking of the datetime module. This task can become complicated due to various import methods and the need for consistent test results. The article discusses common issues that arise when mocking datetime, such as tests failing due to subtle implementation changes and tightly coupled test code. It introduces the freezegun library as a solution, which simplifies testing by providing a freeze_time() decorator that sets a fixed date, ensuring consistent results regardless of import variations. Freezegun is praised for its thoroughness, as it patches multiple datetime methods, offering a more straightforward and reliable alternative to manually crafting mock objects. The article also mentions the libfaketime library for performance-sensitive tests and suggests further reading and resources for those interested in improving their testing practices with fake dates.
Aug 14, 2020
1,020 words in the original blog post.