|
Hi Reader, Regardless of whether you enrolled, thanks for sticking with me through the launch of my new course! π I've already started exploring topics for the next course... π π Link of the weekβgit cheat sheet (PDF) A well-organized and highly readable cheat sheet from Julia Evans, the brilliant mind behind Wizard Zines! π Tip #48: Three ways to set your environment variables in PythonI was playing around with Mistral LLM this weekend (via LangChain in Python), and I needed to set an environment variable in order to provide my API key to Mistral. There are many common reasons you might need to set an environment variable, but they all center around providing configuration details to an application. Below, I'll show you three ways to set an environment variable in Python: Method 1: os.environ The simplest method is to use Python's built-in os module. os.environ acts like a dictionary, and so this code sets an environment variable with the key MISTRAL_API_KEY and the value NotMyRealKey. However, this method isn't secure since your API key is now stored within the code. Method 2: os.environ & getpass This method uses Python's built-in getpass module. When you run this code, a text field appears so that you can paste in your API key. The API key will never be shown on screen, which makes it more secure than method #1, but it's less convenient since you need to paste in your key every time you run the code. Method 3: dotenv This method uses the python-dotenv library, which you can install using pip or conda. All you have to do is create a text file named .env, and then include the key and value as shown here: The load_dotenv function reads the key-value pairs from the file and sets them as environment variables. Assuming you exclude the .env file from your code repository (probably using .gitignore), this is a reasonable method for storing your API key secretly. π See you next week!If you liked this week's tip, please share it with a friend! It really helps me out. - Kevin P.S. Your Life in Weeksβ Did someone AWESOME forward you this email? Sign up here to receive more Data Science tips! |
Join 25,000+ intelligent readers and receive AI tips every Tuesday!
Hi Reader, Until 8 PM ET tonight, you can get the All-Access Pass for $99: Here's everything you need to know: Access all existing courses for one year ($700+ value) Includes new courses launched during your subscription Includes e-book version of Master Machine Learning (coming soon) Additional discounts available Lock in this price forever 30-day refund policy Get the Pass for $99 Questions? Please let me know! - Kevin
Hi Reader, I wanted to share with you three limited-time resources for improving your Python skills... 1οΈβ£ Algorithm Mastery Bootcamp π₯Ύ Are you looking for an intense, 12-day Python bootcamp? My friend Rodrigo GirΓ£o SerrΓ£o is running a new Algorithm Mastery Bootcamp, and it starts in just 5 days! In the bootcamp, you'll solve 24 real programming challenges and participate in daily live sessions to discuss and compare solutions. It's a great way to strengthen your problem-solving muscles πͺ I...
Hi Reader, Last week, I launched the All-Access Pass, which gives you access to ALL of Data School's courses for one year. Through Black Friday, you can buy the pass for $99, after which the price will increase. Here are the included courses: Build an AI chatbot with Python ($9) Create your first AI app in 60 minutes using LangChain & LangGraph! β‘ Build AI agents with Python ($99) Develop the skills to create AI apps that can think and act independently π€ Conda Essentials for Data Scientists...