Quantcast
Channel: Planet Python
Viewing all 22851 articles
Browse latest View live

Matt Layman: Lessons From A Failed SaaS - Building SaaS #37

$
0
0
In this episode, we talked about the things I learned from my SaaS project and some of the reasons why it failed to succeed financially. We dug into the technical and marketing challenges that I faced and what went wrong. I’m shutting down my side project, College Conductor. The SaaS never achieved a sustainable level of success. I started the site to help my wife with her college consulting business.

Roberto Alsina: Python más Pythónico (o: Cómo no parecer un programador Java)

$
0
0

Charla en el Buenos Aires Python Meetup el 7/11/2019 Algunos tips y comentarios sarcásticos para hacer que tu código Python sea más parecido a Python y menos parecido a otra cosa.

Kushal Das: Verified emoji on Mastodon

$
0
0

Yesterday, just for fun, I added an emoji (as a local emoji) to our mastodon instance, kind of look like a verification icon. Only to show the power of federation and Free Software to the new users of Mastodon. Many other users started using the same. But, most newbies to Mastodon got confused with the same

my profile screenshot

my profile edit screenshot

If you see the above screenshot, I just added :verified: after my name in my profile, and that shows the icon. That is not any formal verification. The https://msdtn.social instance also has a similar emoji, but the big https://mastodon.social does not have the same.

Then how to verify someone on Mastodon?

The best way is via their website or blog. If you click to edit your profile, you will find the option to add a few profile metadata, in those sites, you can verify that you own or have edit access of those sites.

my profile link verify

Thus, my blog comes with a green tick on my profile image. Here is to the link verification documentation from the website.

Feel free to follow me on Mastodon.

Kushal Das: oqubeslogging, a PoC for centralized logging in Qubes OS

$
0
0

oqubeslogging is a proof of concept project for Qubes OS. This includes a qrexec service, which allows one AppVM (we will call it logging VM for the rest of the blog post) to have all the logs from different select VMs. This enables central logging among QubesOS land.

The second part is a Python logging handler, which if configured correctly, will allow to pass the logging lines to the logging VM

import logging
from oqubeslogging import OQubesLog

def main():
    handler = OQubesLog("workvm", "loggingvm")
    logging.basicConfig(level=logging.DEBUG, handlers=[handler])
    logger = logging.getLogger("example")

    logger.info("kushal says it works")


if __name__ == "__main__":
    main()

Third, is another example code, which if run as root user in any VM, will collect all logs from journald and pass them to the logging VM.

Why is this useful?

The same reason we use central logging in every place. This will enable us to check only one VM to find the correct log. QubesOS is designed for single user in mind, and instead many random AppVM, we will be able to read and parse logs in that one special logging VM.

PyCharm: PyCharm 2019.3 Beta

$
0
0

We’re very excited to announce the Beta release for PyCharm 2019.3, a feature-complete preview of the upcoming release. Give the Beta build a go and try all the new functionality – download it from our website.

Improvements in PyCharm 2019.3 Beta

  • The issue causing the UI to be unresponsive when an exception was raised while using Python console completion was fixed.
  • We’ve solved the problem causing the Clear All action for the console to raise some errors.
  • Auto generated test files from templates (unittest and pytest) now support classes without methods to generate test files.
  • If you’re using symlinks in your tests you will find that stack traces now consistently will show the symlink instead of the real path in the console.

Further Improvements

For more details on what’s new in this version, please refer to the release notes.

Interested?

Get the PyCharm 2019.3 Beta build from our website. Alternatively, you can use the JetBrains Toolbox App to stay up to date with early builds.
PyCharm 2019.3 Beta is part of Early Access Program, so the EAP rules apply.

EAP Program Key Facts

  • The EAP version of PyCharm Professional Version is free to use
  • EAP build will expire after 30 days
  • This is pre-release software, you may face stability issues and other rough edges
  • You can install the EAP version alongside a stable version of PyCharm
  • EAP versions of PyCharm report statistics by default, you can opt out by changing the settings in Preferences | Appearance & Behavior | System Settings | Data Sharing
  • The latest version of the documentation is now also available

 

PyCharm: Webinar Recording: “Visual SQL Development with PyCharm” with Maxim Sobolevskiy

$
0
0

This week we had a webinar with Maxim Sobolevskiy, the DataGrip Product Marketing Manager, showing the wonderful, magical Database tool in PyCharm. The webinar recording is now available.

In this webinar Max covered many of the amazing features of DataGrip: connections and connection settings, queries with autocomplete and refactoring, working with results, browsing/querying/editing data, export/import, and more. Paul then showed a simple Flask application and how the Database tool is injected into Python code.

If you work at all with SQL in Python projects, take some time to watch the webinar. It’s powerful stuff and will deeply improve your velocity.

The webinar has a sample repository with a Docker Compose setup for the sample PostgreSQL server, along with instructions to recreate the Flask project.

Codementor: Python Project(Descriptions and Code)

$
0
0
This post is showed the descriptions and codes from the projects that I did. Some of them, you can see it from my profile, I put them in the project experience. There are some projects that are for beginners and for there is 1 project that's kinda like for intermediate. All of these projects were from python and python 3 to be more detail. Thank you

Python Anywhere: EU migrations are now live!

$
0
0

In brief: if you have an account on www.pythonanywhere.com you can have it migrated to eu.pythonanywhere.com -- just let us know via email to support@pythonanywhere.com.

If you'd like to know more about what that means, read on...

Back in February, we announced eu.pythonanywhere.com. It's a completely separate version of our site, with all of the computers and storage hosted in Frankfurt, rather than in the US like our other site at www.pythonanywhere.com.

Although our US-based systems are fully GDPR-compliant, thanks to the EU-US Privacy Shield Framework, we appreciate that some people are keen on keeping all of their data inside the EU so as to be sure that they comply with all regulations.

If you're based in the EU, there's almost no downside to using the new system. You will have the comfort of knowing your data is in the EU, and it's closer to you in network terms (in our tests, the network latency is about 8ms from Amsterdam, versus 90ms to our US servers). For paid accounts, billing is in euros so you don't need to worry about foreign exchange fees on your card payments. If we need to perform system maintenance on the servers, we'll do it late at night European time, rather than during the early morning timeslot that we use for the US-based system. The only reason you might want to stick with the US system is that it's a little cheaper; our underlying hosting costs are a bit higher for the EU service, which is reflected in the prices -- a Hacker account that costs US$5/month on the US servers is €5/month on our new system (plus VAT if applicable).

The new system has a good number of users now and is functioning well. We've also been beta-testing a migration system that allows us to move accounts from the US system to the EU one with minimal downtime, and that is working well too :-)

So it's time for us to take that migration system out of beta -- if you have an account on www.pythonanywhere.com and would like it to be moved to eu.pythonanywhere.com, just let us know via email to support@pythonanywhere.com.

Let us know if you have any questions!


Codementor: Managing Class Attributes In Python

$
0
0
Hello guys, in this blog post we are going to dig down into some python progr...

Codementor: Mutable objects vs Python functions.

$
0
0
We know every thing in python is an object and can be classed into mutable and ...

Weekly Python StackOverflow Report: (ccii) stackoverflow python report

$
0
0

Davy Wybiral: Testing 4 Raspberry Pi Gaming Platforms

$
0
0
I've been looking to update my home media center recently and decided to survey the landscape of Raspberry Pi gaming/media platforms. This video compares the four best ones I've been able to find which are: RetroPie, Recalbox, Lakka, and Steamlink.

A. Jesse Jiryu Davis: PyGotham 2019's ASL and Live Captioning Playbook

$
0
0

At PyGotham 2019 we provided live captioning and, for the first time, we offered American Sign Language interpretation and did targeted outreach to groups of Deaf programmers. As a result, we had a half-dozen Deaf attendees, and they reported they were able to fully participate in the conference in a way they hadn’t experienced before. I led our effort to provide ASL and captioning; I hope this recap can serve as a playbook for other conferences.

Quansight Labs Blog: uarray: Attempting to move the ecosystem forward

$
0
0

There comes a time in every project where most technological hurdles have been surpassed, and its adoption is a social problem. I believe uarray and unumpy had reached such a state, a month ago.

I then proceeded, along with Ralf Gommers and Peter Bell to write NumPy Enhancement Proposal 31 or NEP-31. This generated a lot of excellent feedback on the structure and the nuances of the proposal, which you can read both on the pull request and on the mailing list discussion, which led to a lot of restructuring in the contents and the structure of the NEP, but very little in the actual proposal. I take full responsibility for this: I have a bad tendency to assume everyone knows what I'm thinking. Thankfully, I'm not alone in this: It's a known psychological phenomenon.

Read more… (2 min remaining to read)

Twisted Matrix Labs: Twisted 19.10.0 Released

$
0
0
On behalf of Twisted Matrix Laboratories, I am honoured to announce the release of Twisted 19.10! The highlights of this release are:
  • Security fixes for HTTP/2 -- CVE-2019-9512 (Ping Flood), CVE-2019-9514 (Reset Flood), and CVE-2019-9515 (Settings Flood).  Thanks to Jonathan Looney and Piotr Sikora.
  • HTTP/2 fixes regarding timeouts.
  • trial's assertResultOf, failureResultOf, and successResultOf, now accept Deferred-awaiting coroutines.
  • Various other bug fixes for POP3, conch.ssh.keys, and twisted.web.client.FileBodyProducer.
You can find the downloads at <https://pypi.python.org/pypi/Twisted> (or alternatively <http://twistedmatrix.com/trac/wiki/Downloads>). The NEWS file is also available at <https://github.com/twisted/twisted/blob/twisted-19.10.0/NEWS.rst>.

Many thanks to everyone who had a part in this release - the supporters of the Twisted Software Foundation, the developers who contributed code as well as documentation, and all the people building great things with Twisted!

- hawkowl

Mike Driscoll: PyDev of the Week: Vuyisile Ndlovu

$
0
0

This week we welcome Vuyisile Ndlovu (@terrameijar) as our PyDev of the Week! Vuyisile is a contributor to Real Python and a Python blogger on his own website. He is also active in the Python community in Africa. You can find out more about Vuyisile on his website or by checking out his Github profile. Let’s take some time to get to know him better!

VuyisileNdlovu

Can you tell us a little about yourself (hobbies, education, etc):

I’m a developer from Bulawayo, Zimbabwe. I have always been fascinated by computers so after I completed High School, I enrolled for an I.T Diploma program at a local community college that had programming as part of the curriculum. Unfortunately, my situation changed and I couldn’t graduate in the end. I switched to teaching myself computer science topics and programming through online courses and books.

When I’m not working on code, I like to work on woodworking projects in the backyard and taking my dogs for regular walks. Doing this allows me to take a break from tech, be creative in different ways and also get some exercise.

Why did you start using Python?

I was a core contributor to the Mozilla project for a few years and one of the teams I worked with used Python extensively for automating their work. I liked how simple and intuitive Python looked so I started learning it. Compared to C++, which is what I was used to, the Python syntax was easier for me to understand and I loved that it could be used for Web Development, which is an area I have an interest in. As I learned more about the language, I realised that it has an amazing community and since then I’ve made a lot of friends from being a part of the Python community and this is one of the reasons that reinforced my desire to keep using Python.

What other programming languages do you know and which is your favorite?

I don’t have a favorite language yet because I haven’t been programming for a long time and I know that different languages are suited for different things. I’m learning JavaScript and back in college, I took C++ and Visual Basic classes. I teach programming classes at a High School using VB.Net because I find that using Visual Basic makes building GUIs in a Windows environment easy and the language is relatively simple to teach to beginners.

The work projects I work on are web projects and I enjoy using Python and Django to build those out.

What projects are you working on now?

I’m working on a Django customer portal that is powered by a REST API for a Wedding and Events company.

On the side, I’m working on a project that’ll use affordable hardware to make useful websites and services such as PyPI(https://pypi.org/), Wikipedia and Stack Overflow available for offline use because Internet access in Africa is expensive and in some places not always available. I haven’t quite figured out how I’m going to pull this off but it is definitely in the pipeline.

Which Python libraries are your favorite (core or 3rd party)?

A builtin I like is Pathlib, it makes working with the file system simple.

A Third party library I like is pytest, especially it’s test parametrization feature.

How did you end up becoming a blogger?

When I started blogging on my personal site, I did it with the intention of letting other people know how much fun working in Open Source was and to share what I was working on. Now I do it to share my knowledge with the world and also to document my own learning.

I see you are part of the Real Python team. How has that experience been?

Blogging for Real Python has been fantastic, not only do I get paid for articles I write for them, I get better as a writer too because they have very high quality standards and I find those standards influencing my writing outside of Real Python. It’s more than just a blogging site, Real Python is a tightly knit community of really smart people that I enjoy working with.

What exciting things are happening with Python in Africa?

The software development industry is growing rapidly and our business capitals host fintech companies, startups and some big companies like Microsoft, Google, and Amazon that hire locally. We recently held the first PyCon in Ghana and it was massive success. Our community members are championing the use of Python in their companies, schools and Universities. For instance in my country, there’s a whole CyberSecurity Degree that’s taught in Python which is something you don’t see everyday.

Some communities have impressive statistics, a good example is PyCon Namibia 2018, that had 50% male and 50% female attendance. We also have developers who are working towards shaping the direction of Python and popular Python projects such as Django. Names I can think of are Joannah Nanjekye, who is an author and member of the Python Core Team, Marlene Mhangami who is a Director at the Python Software Foundation and Anna Makarudze, the Vice President of the Django Software Foundation

Is there anything else you’d like to say?

Yes, If you’re reading this and your team is hiring, I’d love to have a chat 🙂 You can find my contact details on my website.

Thanks for doing the interview, Vuyisile!

The post PyDev of the Week: Vuyisile Ndlovu appeared first on The Mouse Vs. The Python.

Python Software Foundation: Seeking Developers for Paid Contract Improving pip

$
0
0

The Python Software FoundationPackaging Working Group is receiving funding to work on the design, implementation, and rollout of pip's next-generation dependency resolver. (We'll be able to publicly name the funders later this month and in early December.)

pip is the official package installer for Python. pip aims to make it easy for the millions of people who use Python to download and install Python libraries and applications (open source and closed source, source and binary, globally and within isolated virtual environments). It's a foundational component of the Python ecosystem and broader computer software and technology landscape.

This project aims to complete the design, implementation, and rollout of pip's next-generation dependency resolver. This will lower the barriers to installing Python software, empowering users to get a version of a package that works. It will also lower the barriers to distributing Python software, empowering developers to make their work available in an easily reusable form.

Because of the size of the project, funding has been allocated to secure two contractors, a senior developer and an intermediate developer, to work on development, testing and building test infrastructure, code review, bug triage, and assisting in the rollout of necessary features.

We plan to begin the project in Quarter 1 of 2020. We are also interested in senior developer candidates who are available to start in December 2019.

Timeline and budget

DateMilestone
November 11Request for Proposal period opens.
November 22Request for Proposal period closes.
November 27Date proposals will have received a decision.
December 31Latest date for contracts for accepted proposals to be finalized.
January 2Latest date for contract work to commence.

Role 1: We seek a senior Python developer, work starting in mid-December 2019 or early January 2020, work ending at the end of May 2020. Pay: $116,375 total (665 hours of work at $175 per hour).

Role 2: We seek an intermediate-to-senior Python developer, work starting in early January 2020, till the end of December 2020. Pay: $103,700 (670 hours of work at $150 per hour), plus $1600 budgeted for onboarding travel and $1600 budgeted for PyCon travel.

What is the Request for Proposals period?

A Request for Proposals (RFP) is a process intended to allow us (the Python Software Foundation) to collect proposals from potential contractors and select contractor(s) best suited to fulfill the specified work.

After the RFP period closes we will evaluate the received proposals based on the evaluation criteria, seek clarification from proposers as necessary, and select one or more contractors to complete the work specified in the scope section.

Note: This Request For Proposal document may be updated to reflect things that we learn during the process. The canonical version and history is available here.

How do I submit a proposal?

First, please read the full contents of the Request for Proposals!

You'll find the instructions for submission, evaluation criteria, as well as the scopes of the two roles, there.

Real Python: PyCon Africa 2019 (Recap)

$
0
0

PyCon Africa was a wonderful, inspiring, and technically enlightening conference that took place in Accra, Ghana from August 6 to 10, 2019 at the University of Ghana. This conference was the very first pan-African conference for Python developers and was attended by 323 Pythonistas from 26 different countries. Most of the attendees traveled from countries around Africa, and a number of speakers came from the US, the Netherlands, Germany, Brazil, and Italy.

Python is becoming more and more adopted all across the globe. In Africa, Python is earning a special place for itself, where it’s used extensively for web development and data science. African businesses are looking for developers with Python skills in these areas, and having a PyCon in Africa provides a foundation to help support African programmers.

Free Bonus:5 Thoughts On Python Mastery, a free course for Python developers that shows you the roadmap and the mindset you'll need to take your Python skills to the next level.

What Happened at PyCon Africa

On the day before the main conference started, attendees took some time to settle in. Those who were just getting started with Python attended a Beginners Day Session led by Joey Darko to help them set up their computers for Python development. I joined another group of international travelers on a tour of Accra, Ghana. We visited many tourist sites such as the Independence Square, the cultural center, and some of the local markets to get a feel for the Ghanaian way of life.

PyCon Africa Delegates On A Tour Of AccraImage: KhoPhi.Photography

The following day was dedicated to workshops, with two running concurrently in both the morning and afternoon sessions. The Django Girls workshop introduced women and Django beginners to Django development. Other workshops were focused on concepts like data visualization, testing, and iterators.

Django Girls Group PhotoDjango Girls (Image: KhoPhi.Photography)

Main Conference

The main conference started on August 8 and kicked off with an opening ceremony that featured traditional Ghanaian dance and welcoming remarks from Marlene Mhangami, the Python Africa Chair. Each day of the conference had an opening and closing keynote talk.

Traditional Ghanaian dancersTraditional Ghanaian dance (Image: KhoPhi.Photography) Marlene Mhangami KeynoteWelcoming remarks by Marlene Mhangami (Image: KhoPhi.Photography)

Let’s take a look at some of the talks that were given over the two days of the conference.

Moustapha Cisse: The Potential for Positive Impact Through AI

Moustapha Cisse is the head of Google’s AI Center in Accra and he gave the opening keynote on the first day of the main conference. Moustapha’s talk was about how African technologists can use technology to solve African problems. In his talk, he discussed some of the work he’s involved in at Google and in the AI space, like using Artificial Intelligence for disease prediction, and satellite images to gather information and statistics for AI-enabled flood forecasting.

Moustapha Cisse PyCon Africa TalkMoustapha Cisse, Head of Google AI Center Accra (Image: KhoPhi.Photography)

Meili Triantafyllidi: Lessons Learned From 6 Years in PyLadies Berlin

Meili Triantafyllidi is the co-founder of PyLadies Berlin. There are a number of PyLadies and women-focused Python user groups around Africa. These groups are doing a lot of amazing work, but like anything in life, there’s always room for improvement.

Meili Triantafyllidi gave a timely talk on the lessons she learned from six years of running PyLadies Berlin. In her talk, she shared tips and best practices for making events more inclusive, accessible, and safe. Her talk also covered information on how to run events, get the right speakers, and improve public speaking skills.

Meili Triantafyllidi PyLadies talkMeili Triantafyllidi (Image: KhoPhi.Photography)

A PyLadies meeting was held after Meili’s talk. The meeting established a common purpose and plans to support female programmers in Africa, including through the creation of a dedicated PyLadies Africa channel in the PyLadies Slack group.

Candy Tricia Khohliwe: Web Virtual Reality and A-Frame

Candy Khohliwe, a Mozilla Tech Speaker, gave a talk about WebVR, an open technology that allows you to experience virtual reality in your browser no matter what device you use. The focus of Candy’s talk was A-Frame, a web framework for creating 3D and WebVR experiences using HTML. From this informative talk, I learned how to use A-Frame to create and draw WebVR components. I look forward to trying it out in future projects!

Candy Khohliwe WebVR TalkCandy Tricia Khohliwe (Image: KhoPhi.Photography)

Nicholas Del Grosso: Unravelling the Spaghetti (Tips for Refactoring Your Code)

Nick Del Grosso gave a talk on refactoring code. He explained how project code can get messy and took us through the process of refactoring it safely. He also discussed strategies for identifying dead code, choosing good variable names, and using tools to help refactor code.

Nicholas Del Grosso PyCon Africa TalkNicholas Del Grosso (Image: KhoPhi.Photography)

Jessica Upani: Is This Python Thing Really Working?

Jessica Upani from the Namibian Python community gave an enlightening talk about the different Python community groups in Namibia. She discussed the challenges they overcame and what lessons other African Python communities can learn from them.

Jessica  Upani PyCon Africa TalkImage: Khophi.Photography

Kelvin Oyana: Bridging the Talent Gap Between Python Communities and Industry

Kelvin’s talk was about the divide between what companies expect from developers and what developers can actually do. He also offered insight into how this gap can be bridged, both by communities and individual developers.

Kelvin Oyana Pycon Africa TalkKelvin Oyana (Image: Khophi.Photography)

Daniele Procida: The World’s Simplest, Cheapest Plotter

Daniele Procida is a Django core developer and one of the members of the PyCon Africa organizing team. In his talk, Daniele presented an interesting project: a simple pen plotter he built using cardboard, a Rasberry Pi, some servo motors, and Python software. His project embodies the spirit of resourcefulness and innovation that characterizes African enterprise.

Daniele Procida PyCon Africa TalkDaniele Procida (Image: Khophi.Photography)

Ewa Jodlowska: Keynote

Ewa Jodlowska, the Executive Director of the Python Software Foundation (PSF), gave a keynote talk about the PSF, how it works with the global community, and its plans for the future. Ewa shed more light on the different programs the PSF runs to foster the growth of the Python community, such as the Sponsorship Program and the Python Ambassador Program in South America.

Ewa Jodlowska PyCon Africa Keynote TalkEwa Jodlowska (Image: Khophi.Photography)

Anna Makarudze: What the African Developer Can Do to Increase Diversity in Tech

Anna Makarudze gave the closing keynote on the first day of the main conference. She’s a Software Engineer at BriteCore (one of the diamond sponsors of PyCon Africa), the Vice President of the Django Software Foundation, and the Fundraising Coordinator for the Django Girls Foundation. Anna drew on her experiences in these organizations to discuss how conferences, organizations, and individual developers can increase diversity figures in tech.

Panel Discussion: The Role of the African Python Developer in the Community

There was a panel discussion of leaders in business, technology, and community development. Marlene Manghami moderated the discussion on the role of the African Python community in the global tech space. Her panelists were Solomon Apenya, Daniel Roy Greenfeld, and James Yankah.

Solomon Apenya is a Senior Consultant at Andela, a company that finds and builds distributed engineering teams in Africa. Daniel Roy Greenfeld is co-author of Two Scoops of Django and VP of Implementation Engineering at BriteCore. James Yankah is the Managing Director of Brompton Group, a group of companies that offer recruitment, training, management, logistics, and security services.

Panel Discussion At PyCon AfricaImage: Khophi Photography

Anthony Shaw: Standing Out in a World of 20 Million Developers

On the last day of the conference, I had the pleasure of meeting and listening to Anthony Shaw, a fellow Real Python author. Anthony gave a talk targeted at new developers to help them succeed in their development careers. In the talk, Anthony discussed ways to get ahead, grow your skill set, learn new technologies, and fight doubt and impostor syndrome. He concluded with tips on how to nail technical interviews.

Anthony Shaw PyCon Africa TalkAnthony Shaw (Image: Khophi.Photography)

Closing Keynote: Kojo Idrissa

The closing keynote on the last day of the conference was given by Kojo Idrissa, an organizer for DjangoCon and a Django Events Foundation North America (DEFNA) Ambassador. Kojo reflected on lessons from the past and how the African diaspora has had an effect on us all.

Kojo Idrissa PyCon Africa TalkKojo Idrissa (Image: Khophi.Photography)

Sprints Day

The day after the main conference was dedicated to sprints! This is where people group up to work on various open source Python projects. I was part of a team that worked on Cookie Cutter and other related projects. I submitted a PR that got merged into the project and I also helped mentor other team members.

I highly recommend anyone who has not attended a sprint before to do so! It’s a great way to practice your skills, contribute to an open source project, and meet the developers involved with the project.

A Group Of Developers During A Sprints Session At Pycon AfricaSprints (Image: Khophi.Photography)

Summary

PyCon Africa was a huge success and nothing short of fantastic! It was a good start for the African community because it brought together, for the first time, Python developers from the different African Python communities. It also allowed us to hear from representatives of the PSF about how the Python community is organized and funded. For many, this was the first time that people from the different communities met in person after years of online collaboration.

PyCon Africa Group PhotoImage: Khophi Photography

For me, the experience was worth the sacrifice and expense because I got to meet and talk to people from all over the world and learn about how they use Python in their work or studies. I gave a lightning talk on how to send desktop notifications from Python scripts using Python and other tools native to Linux.

Another highlight of attending PyCon Africa was that I got to meet many of our readers, and a number of them attributed their success to much of the content they read here on Real Python. Anthony Shaw and I also gave away many Real Python stickers. Here’s a photo we took with Edison, a friend and Real Python reader:

Real Python Authors and Reader: Vuyisile, Anthony, And Edison

One problem that the organizers faced was making the conference affordable to as many people as possible. Travel within Africa is expensive and difficult for many Africans. For instance, an entry visa to Ghana alone costs $100 to $200 U.S. dollars. Add to that the cost of travel and lodging, and the event was out of reach for many people who were interested in attending.

Voluntary donations from individuals and corporate sponsorship from Real Python, BriteCore, Andela, and several other sponsors helped cover the cost of tickets, accommodation, and travel for those that needed it. If you’d like to get more African people involved in Python, then consider supporting future Python events in Africa and hiring African developers to work remotely in your teams.

At the time of this writing, videos from the conference have not been made available, but there is a highlight video that also features interviews with some of the attendees. You can also read the official report from the conference organizers. If you’re thinking of attending a PyCon near you, then check out How to Get the Most Out of PyCon.


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Erik Marsja: Tutorial: How to Read Stata Files in Python with Pandas

$
0
0

The post Tutorial: How to Read Stata Files in Python with Pandas appeared first on Erik Marsja.

In this post, we are going to learn how to read Stata (.dta) files in Python.

As previously described (in the read .sav files in Python post) Python is a general-purpose language that also can be used for doing data analysis and data visualization. One example of data visualization will be found in this post.

One potential downside, however, is that Python is not really user-friendly for data storage. This has, of course, lead to that our data many times are stored using Excel, SPSS, SAS, or similar software. See, for instance, the posts about reading .sav, and sas files in Python:

Can I Open a Stata File in Python?

We are soon going to practically answer how to open a Stata file in Python? In Python, there are two useful packages called Pyreadstat, and Pandas that enable us to open .dta files. If we are working with Pandas, the  read_stata method will help us import a .dta into a Pandas dataframe. Furthermore, the package Pyreadstat, which is dependent on Pandas, will also create a Pandas dataframe from a .dta file.

How to install Pyreadstat:

First, before learning how to read .dat files using Python and Pyreadstat we need to install it. As many Python packages this package can be installed using pip or conda:

  1. Install Pyreadstat using pip:
    Open up the Windows Command Prompt and type pip install pyreadstat
    How to install pyreadstat
  2. Install using Conda:
    Open up the Anaconda Prompt, and type conda install -c conda-forge pyreadstat

How to Open a Stata file in Python

In this section, we are finally ready to learn how to read a .dta file in Python using the Python packages Pyreadstat and Pandas.

How to Load a Stata File in Python Using Pyreadstat

In this section, we are going to use pyreadstat to import a .dta file into a Pandas dataframe. First, we import pyreadstat:

import pyreadstat

Second, we are ready to import Stata files using the method read_dta. Note that, when we load a file using the Pyreadstat package, it will look for the .dta file in Python’s working directory. In the read Stata files example below, the FifthDaydata.dta is located in a subdirectory (i.e., “SimData”).

dtafile = './SimData/FifthDayData.dta'
df, meta = pyreadstat.read_dta(dtafile)

In the code chunk above, two variables were created; df, and meta. If we use the Python function type we can see that “df” is a Pandas dataframe:

This means that we can use all the available methods for Pandas dataframe objects. In the next line of code, we are Pandas head method to print the first 5 rows.

df.head()

Learn more about working with Pandas dataframes in the following tutorials:

How to Read a Stata file with Python Using Pandas

In this section, we are going to read the same Stata file into a Pandas dataframe. However, this time we will use Pandas read_stata method. This has the advantage that we can load the Statafile from a URL.

Before we continue, we need to import Pandas:

import pandas as pd

Now, when we have done that, we can read the .dta file into a Pandas dataframe using the read_stata method. In the read Stata example here, we are importing the same data file as in the previous example.

After we have loaded the Stata file using Python Pandas, we print the last 5 rows of the dataframe with the tail method.

dtafile = './SimData/FifthDayData.dta'

df = pd.read_stata(dtafile)
df.tail()

How to Read .dta Files from URL

In this section, we are going to use Pandas read_stata method, again. However, this time we will read the Stata file from a URL.

url = 'http://www.principlesofeconometrics.com/stata/broiler.dta'

df = pd.read_stata(url)
df.head()

Note, the only thing we changed was we used a URL as input (url) and Pandas read_stata will import the .dta file that the URL is pointing to.

Pandas Scatter Plot

Here, we will create a scatter plot in Python using Pandas scatter method. This is to illustrate how we can work with data imported from .dta files.

df.plot.scatter(x='pchick',
                       y='cpi')
Scatter plot in PythonScatter Plot in Python

Learn more about data visualization in Python:

How to Read Specific Columns from a Stata file

Now using pyreadstat read_dta and Pandas read_stat both enables us to read specific columns from a Stata file. Note, that read_dta have the argument usecols and Pandas the argument columns.

Reading Specific Columns using Pyreadstat

In this Python read dta example, we use the argument usecols that takes a list as parameter.

import pyreadstat

dtafile = './SimData/FifthDayData.dta'
df, meta = pyreadstat.read_dta(dtafile,
                              usecols=['index', 'Name', 'ID',
                                      'Gender'])
df.head()
Dataframe created from Stata fileDataframe from .dta

Reading Specific Columns using Pandas read_stata

Here, we are going to use Pandas read_stata method and the argument columns. This argument, as in the example above, takes a list as input.

import pandas as pd
url = 'http://www.principlesofeconometrics.com/stata/broiler.dta'

df = pd.read_stata(url,
                  columns=['year', 'pchick', 'time',
                                      'meatex'])
df.head()
Pandas read_stata to DataframeDataframe

Note, the behavior of Pandas read_stata; in the resulting dataframe the order of the column will be the same as in the list we put in.

How to Save a Stata file

In this section of the Python Stata tutorial, we are going to save the dataframe as a .dta file. This is easily done, we just have to use the write_dta method when using Pyreadstat and the dataframe method to_stata in Pandas.

Saving a dataframe as a Stata file using Pyreadstat

In the example below, we are using the dataframe we created in the previous section and write it as a dta file.

pyreadstat.write_dta(df, 'broilerdata_edited.dta')

Now, between the parentheses is where the important stuff happens. The first argument is our dataframe and the second is the file path. Note, only having the filename, as in the example above, will make the write_dta method to write the Stata file to the current directory.

How to Save a dataframe as .dta with Pandas to_stata

In this example, we are going to save the same dataframe using Pandas to_stata:

df.to_stata('broilerdata_edited.dta')

As can be seen in the image above, the dataframe object has the to_stata method. Within, the parentheses we put the file path.

Save a CSV file as a Stata File

In this section, we are going to work with Pandas read_csv to read a CSV file, containing data. After we have imported the CSV to a dataframe we are going to save it as a .dta file using Pandas to_stat:

df = pd.read_csv('./SimData/FifthDayData.csv')
df.to_stata('./SimData/FifthDayData.dta')

Export an Excel file as a Stata File

In the final example, we are going to use Pandas read_excel to import a .xslx file and then save this dataframe as a Stata file using Pandas to_stat:

df = pd.read_excel('./SimData/example_concat.xlsx')
df.to_stata('./SimData/example_concat.dta')

Note, that in both of the last two examples above we save the data to a folder called SimData. If we want to save the CSV and Excel file to the current directory we simply remove the “./SimData/” part of the string.

Learn more about importing data using Pandas:

Note, all the files we have read using read_dta, read_stata, read_csv, and read_excel can be found here. It is, of course, possible to open SPSS and SAS files using Pandas and save them as .dta files as well.

Summary: Read Stata Files using Python

In this post, we have learned how to read Stata files in Python. Furthermore, we have learned how to write Pandas dataframes to Stata files.

The post Tutorial: How to Read Stata Files in Python with Pandas appeared first on Erik Marsja.

Podcast.__init__: Automate Your Server Security With GrapheneX

$
0
0
The internet is rife with bots and bad actors trying to compromise your servers. To counteract these threats it is necessary to diligently harden your systems to improve server security. Unfortunately, the hardening process can be complex or confusing. In this week's episode 18 year old Orhun Parmaksiz shares the story of how he and his friends created the GrapheneX framework to simplify the process of securing and maintaining your servers using the power and flexibility of Python. If you run your own software then this is definitely worth a listen.

Summary

The internet is rife with bots and bad actors trying to compromise your servers. To counteract these threats it is necessary to diligently harden your systems to improve server security. Unfortunately, the hardening process can be complex or confusing. In this week’s episode 18 year old Orhun Parmaksiz shares the story of how he and his friends created the GrapheneX framework to simplify the process of securing and maintaining your servers using the power and flexibility of Python. If you run your own software then this is definitely worth a listen.

Announcements

  • Hello and welcome to Podcast.__init__, the podcast about Python and the people who make it great.
  • When you’re ready to launch your next app or want to try a project you hear about on the show, you’ll need somewhere to deploy it, so take a look at our friends over at Linode. With 200 Gbit/s private networking, scalable shared block storage, node balancers, and a 40 Gbit/s public network, all controlled by a brand new API you’ve got everything you need to scale up. And for your tasks that need fast computation, such as training machine learning models, they just launched dedicated CPU instances. Go to pythonpodcast.com/linode to get a $20 credit and launch a new server in under a minute. And don’t forget to thank them for their continued support of this show!
  • Having all of your logs and event data in one place makes your life easier when something breaks, unless that something is your Elastic Search cluster because it’s storing too much data. CHAOSSEARCH frees you from having to worry about data retention, unexpected failures, and expanding operating costs. They give you a fully managed service to search and analyze all of your logs in S3, entirely under your control, all for half the cost of running your own Elastic Search cluster or using a hosted platform. Try it out for yourself at pythonpodcast.com/chaossearch and don’t forget to thank them for supporting the show!
  • You listen to this show to learn and stay up to date with the ways that Python is being used, including the latest in machine learning and data analysis. For even more opportunities to meet, listen, and learn from your peers you don’t want to miss out on this year’s conference season. We have partnered with organizations such as O’Reilly Media, Dataversity, Corinium Global Intelligence, Alluxio, and Data Council. Upcoming events include the combined events of the Data Architecture Summit and Graphorum, the Data Orchestration Summit, and Data Council in NYC. Go to pythonpodcast.com/conferences to learn more about these and other events, and take advantage of our partner discounts to save money when you register today.
  • Your host as usual is Tobias Macey and today I’m interviewing Orhun Parmaksiz about GrapheneX, a framework for simplifying the process of hardening your servers

Interview

  • Introductions
  • How did you get introduced to Python?
  • Can you start by explaining what we mean when we talk about hardening of servers?
  • What are the common ways of hardening a system, which techniques can we use for this purpose?
  • What are some of the high level categories of threats that operators should be considering?
  • What is GrapheneX and what was your motivation for creating it?
    • How does GrapheneX aid users in the process of increasing the security of their infrastructure?
    • Is any extra operating system knowledge required for using GrapheneX?
  • Can you talk through the workflow for someone using GrapheneX to harden their systems?
    • What options does it support for managing deployment across a fleet of servers?
  • Some security controls can actually prevent proper operation of the applications and services that are deployed on a server. How do you approach preventing those scenarios or educating the users in determining which controls are appropriate?
  • Why did you choose Python for a project like GrapheneX?
  • How is GrapheneX implemented?
    • How has the design evolved since you first began working on it?
    • If you were to start the project over today, what would you do differently?
  • Do you accept contributions to the framework? If so, what kind of contributions are needed for improving GrapheneX?
  • For someone who is interested in adding a new module to the framework, what is involved?
  • What have you found to be the most interesting or challenging aspects of your work on GrapheneX?
  • What, if any, aspects of server security have you consciously avoided implementing in GrapheneX?
  • What are your future plans about the GrapheneX?

Keep In Touch

Picks

Closing Announcements

  • Thank you for listening! Don’t forget to check out our other show, the Data Engineering Podcast for the latest on modern data management.
  • Visit the site to subscribe to the show, sign up for the mailing list, and read the show notes.
  • If you’ve learned something or tried out a project from the show then tell us about it! Email hosts@podcastinit.com) with your story.
  • To help other people find the show please leave a review on iTunes and tell your friends and co-workers
  • Join the community in the new Zulip chat workspace at pythonpodcast.com/chat

Links

The intro and outro music is from Requiem for a Fish The Freak Fandango Orchestra / CC BY-SA

Viewing all 22851 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>