<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: daCoder</title>
    <description>The latest articles on Forem by daCoder (@dacoder).</description>
    <link>https://forem.com/dacoder</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F916828%2F6d8a520e-b81f-44e5-8b01-d38255fbe47d.png</url>
      <title>Forem: daCoder</title>
      <link>https://forem.com/dacoder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dacoder"/>
    <language>en</language>
    <item>
      <title>IP to Geolocation with Python</title>
      <dc:creator>daCoder</dc:creator>
      <pubDate>Sun, 04 Sep 2022 12:00:49 +0000</pubDate>
      <link>https://forem.com/dacoder/ip-to-geolocation-with-python-1hi4</link>
      <guid>https://forem.com/dacoder/ip-to-geolocation-with-python-1hi4</guid>
      <description>&lt;h2&gt;
  
  
  OR - My Own Headless SAAS - Part 2
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/dacoder/my-own-headless-saas-part-1-where-i-begin-420c"&gt;In my previous&lt;/a&gt; post I described how I began developing my own SAAS and the different decisions I had to make.&lt;/p&gt;

&lt;p&gt;Here I want to show you how I (and you can too!) develop an IP-to-geo service using Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;Before going in deep, we must realize that translating an IP address into a geolocation is a tricky business. IPs are commonly allocated by ranges (i.e. sets of hundreds or more IPs) to large organizations and associations, governments, ISPs, and large companies. &lt;/p&gt;

&lt;p&gt;Those organizations then allocate those IPs as they see fit, either internally, or for publicly accessible resources, and sometimes even to users (e.g. ISPs may allocate IP to an internet consumer, and one can purchase a fixed IP from cloud providers).&lt;br&gt;&lt;br&gt;
However IP allocation tend to change with time, making it difficult to maintain an accurate mapping of IP to organization or IP to location. &lt;/p&gt;

&lt;p&gt;This is why there're several businesses out there that specialize in that exclusively - maintaining a constantly updated map of IPs, allocations and locations.&lt;br&gt;
Among those firms are &lt;a href="https://www.maxmind.com/en/geoip2-databases"&gt;Maxmind&lt;/a&gt;, &lt;a href="https://www.ip2location.com/"&gt;IP2Location&lt;/a&gt;, &lt;a href="https://db-ip.com/"&gt;DP-IP&lt;/a&gt;, and more.&lt;/p&gt;

&lt;p&gt;On this piece I'll use Maxmind's IP free database, and I'll show you how to read is using Python.&lt;br&gt;
&lt;em&gt;Note that the GeoLite database is a free, limited and inaccurate version of Maxmind's full database, which requires a license.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Code it!
&lt;/h3&gt;

&lt;p&gt;If you're lazy, you can also checkout &lt;a href="https://github.com/dacoderc/notebooks/blob/main/ip_to_geolocation.ipynb"&gt;my notebook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lets get started:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?lang=en"&gt;Register to MaxMind&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Once you're in, go ahead to the "download database" section:
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IAUkh0VI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iggjhxjimf8pd8m6ku6e.png" alt="Download database" width="880" height="491"&gt;
&lt;/li&gt;
&lt;li&gt;Next, scroll down and download the "GeoLite City" database. Make sure to download the GZIP and not the CSV file.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UX5FgO5b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7kyke1esibil99s1hw1.png" alt="Download GeoLite City GZIP" width="880" height="442"&gt;
&lt;/li&gt;
&lt;li&gt;Extract and put the .mmdb file somewhere next to your code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Next we do some simple coding.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To read this database we'll use Maxmind's own python library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install geoip2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My geo.py file looks as follows, and I guess it's quite straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import geoip2.database

# Open the database file, the location of the database needs to match your setup
with geoip2.database.Reader('./files/GeoLite2-City.mmdb') as reader:

    # Query for a specific IP
    response = reader.city('90.190.169.0')
    print(f"Continent: {response.continent.names['en']}")
    print(f"Country: {response.country.names['en']}")
    print(f"City: {response.city.names['en']}")
    print(f"Coordinates: Lat {response.location.latitude} Long {response.location.longitude}")
    print(f"Timezone: {response.location.time_zone}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example I merely print out some data returned from Maxmind's database, but I can do much more, such as keeping it into my DB, use it for logging, user verification, cyber prevention, etc.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Are you considering to add IP-to-location capabilities to your app?&lt;/strong&gt;&lt;br&gt;
If so, you can definitely go ahead and purchase Maxmind's (or any other firm's) IP-to-geo database file, and implement it into your code.&lt;br&gt;
The advantages for this approach is that you get a robust and independent app. &lt;br&gt;
The disadvantages for this approach is that you'll need to purchase a license regardless of your usage, and you'll forever need to make sure that the database file is being constantly updated into your codebase. &lt;br&gt;
This takes another (micro)service to develop, maintain and monitor.&lt;/p&gt;

&lt;p&gt;Another wise alternative is to use an API service to query for IP-to-location.&lt;br&gt;
If you're considering this approach, make sure to check out my own &lt;a href="https://www.tooltap.app/"&gt;tooltap.app&lt;/a&gt; service. &lt;/p&gt;




&lt;p&gt;I'm still adding users as design partners with exclusive early-bird benefits. Contact me if you wish to enjoy this opportunity.&lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>api</category>
    </item>
    <item>
      <title>My own Headless SAAS - Part 1: Where I begin</title>
      <dc:creator>daCoder</dc:creator>
      <pubDate>Tue, 30 Aug 2022 16:08:32 +0000</pubDate>
      <link>https://forem.com/dacoder/my-own-headless-saas-part-1-where-i-begin-420c</link>
      <guid>https://forem.com/dacoder/my-own-headless-saas-part-1-where-i-begin-420c</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/dacoder/developing-my-own-headless-api-service-3dem"&gt;In my previous post&lt;/a&gt; I described the background and reasons that lead me to begin developing my own SAAS: &lt;a href="https://www.tooltap.app/"&gt;Tooltap&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Here I want to describe on my first steps and how I decided to focus my effort.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision #1 - Main business domain
&lt;/h3&gt;

&lt;p&gt;Or in other words - what do I want to develop?&lt;br&gt;
This was my first area to consider, and it did take me a while, but finally i fixed my mind on Headless SAAS that delivers a set of common-usage APIs.&lt;/p&gt;

&lt;p&gt;The reasons for that are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I wanted something within my skillset and passion, and APIs have always been there for me&lt;/li&gt;
&lt;li&gt;I do frontend, but I really prefer not to. and;&lt;/li&gt;
&lt;li&gt;During years of leading dev teams, I was walking through so many stylish SAASs, spending my time on understanding their interfaces, registrations and more registrations, just to finally get to the API and take my API keys.
I want to create a service that doesn't need all that.&lt;/li&gt;
&lt;li&gt;I can get to a Headless SAAS MVP within days, not months. &lt;/li&gt;
&lt;li&gt;The demand for APIs is always increasing, as more SAAS and new software comes to light. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Decision #2 - My minimum viable product
&lt;/h3&gt;

&lt;p&gt;My requirements from an MVP are to be usable and valuable, meaning a user should be able to use it without contacting me, and immediately gain value. &lt;br&gt;
To achieve that I realized I need to build:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic user management with a Sign up and a method to retrieve auth keys - all based on APIs&lt;/li&gt;
&lt;li&gt;The actual API service itself - which must be simple but valuable (touch on that later)&lt;/li&gt;
&lt;li&gt;Documentation - API docs which adhere to OpenAPI standard and manuals to quickly get the developer set up and working with my service. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Decision #3 - The service itself
&lt;/h3&gt;

&lt;p&gt;I was seeking for a service that is an API by nature, relatively easy for me to implement (MVP within days!!) and with a high market demand. &lt;br&gt;
Scrolling through RapidAPI's list of most common APIs, I realized the one answering my requirements is the &lt;strong&gt;IP-to-Geolocation&lt;/strong&gt; API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y1EvfO7Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clur7epvwmspydxr6qge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y1EvfO7Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clur7epvwmspydxr6qge.png" alt="RapidAPI most common APIs" width="880" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;IP-to-Geolocation is one of the most commonly used APIs out there, merely because every SAAS or web app with users traffic needs it. &lt;br&gt;
Developers who're required to add IP-to-geo functionality to their apps can develop it in-house, but the better choice is to consume it as a service since &lt;em&gt;it's cheap to consume but expensive to maintain&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Yeah I know. There're gazillion IP-to-Geo services out there. &lt;br&gt;
But again, the demand is always rising, it's classic for an MVP, and I do sincerely believe that once I get more services in, then also this one will gain traffic. &lt;/p&gt;

&lt;h3&gt;
  
  
  Decision #4 - Tools &amp;amp; Framework
&lt;/h3&gt;

&lt;p&gt;Here the decision was the easiest for me. &lt;br&gt;
A non-popular opinion ahead: Javascript is ugly, node makes me a headache, Python is my true love &amp;lt;3.&lt;br&gt;
There I said it. &lt;br&gt;
I know people like to fancy their React, Vue, Node.js skills nowadays. But as someone who's been here since native JS, through Prototype.js, jQuery, underscore, backbone, handlebars and so on. And then seeing the development of PHP frameworks since PHP3, Ruby and RoR, and so many others...&lt;br&gt;
I have to break this to you once and for all: Django got it spot-on since 2010.&lt;br&gt;
So you guessed it, I'm proudly building on the wonderful Django framework with Python3.9.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision #5 - Website and documentation
&lt;/h3&gt;

&lt;p&gt;I'm focusing on building it headless, so to begin with I decided on a no-website.&lt;br&gt;
However, I still need to host some API docs and manuals, and for that I decided on having a &lt;a href="https://github.com/dacoderc/tooltap-docs"&gt;documentation repository on Github&lt;/a&gt;, and by using github-pages it translates into a &lt;a href="https://www.tooltap.app"&gt;website under my own domain&lt;/a&gt;.&lt;br&gt;
To ease up the API docs experience I created a workspace on Stoplight, which's hosting my &lt;a href="https://tooltap.stoplight.io/docs/tooltap-api-services/7aryd43e1osva-tool-tap-api-services"&gt;OpenAPI docs&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next post:&lt;/strong&gt; On the IP-to-Geo API and my roadmap&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I'm still adding users as design partners with exclusive early-bird benefits. Contact me if you don't want to miss this opportunity.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>headles</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Developing my own Headless API service - Part 0</title>
      <dc:creator>daCoder</dc:creator>
      <pubDate>Sun, 28 Aug 2022 14:18:12 +0000</pubDate>
      <link>https://forem.com/dacoder/developing-my-own-headless-api-service-3dem</link>
      <guid>https://forem.com/dacoder/developing-my-own-headless-api-service-3dem</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;So I decided to use my own skills and open my own self-sustainable business.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hello readers, I call myself daCoder, and my story begins far back, since MS-DOS and Basic, when I was developing for fun and study. &lt;/p&gt;

&lt;p&gt;Then at the break of Web2.0 I even started my own business, a web B2B e-commerce service. I developed, team-lead, VP-R&amp;amp;D and CTO'ed.&lt;br&gt;
And it was a booming... &lt;br&gt;
But then it wasn't about development anymore, it was management, planning, strategies... and other managers... and business and more business. &lt;br&gt;
&lt;em&gt;And then the spark slowly faded away.&lt;/em&gt; 😔&lt;/p&gt;

&lt;h3&gt;
  
  
  So finally I retired...
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;but now what?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As a developer, I have 20+ years expertise in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend - PHP, Python, Java, C (CGI and stuff), Perl&lt;/li&gt;
&lt;li&gt;Frontend - since the happy days of native JS to nowadays React &lt;/li&gt;
&lt;li&gt;Devops - from before it was called devops. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But I've always been drawn to backend, architecture, and scaling systems.&lt;br&gt;
Thats my passion 🤩&lt;/p&gt;

&lt;p&gt;So I decided to use my own skills and open my own self-sustainable business, focusing on API services and developers.&lt;/p&gt;

&lt;p&gt;Yeah, I know. There're soooo many services alike.&lt;br&gt;&lt;br&gt;
In fact, for each of the APIs I'm writing and about to add there're numerous well-established and deeply focused businesses. &lt;/p&gt;

&lt;p&gt;However, my orientation is to focus on simplicity, minimalism, and as much as accurate as possible.&lt;br&gt;&lt;br&gt;
This means that &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Services should be API first, with consumable OpenAPI documentation.&lt;/li&gt;
&lt;li&gt;It should be Developer readable first, UI later&lt;/li&gt;
&lt;li&gt;Deliver APIs that will solve the your development tasks faster and more sustainable than adding a library in your code&lt;/li&gt;
&lt;li&gt;Fairness &amp;amp; transparency - you get what you pay for, and you pay for what you get. No hidden fees, no "subscriptions" when it doesn't make sense.&lt;/li&gt;
&lt;li&gt;Put it all under one umbrella, so you don't have to seek and partner with so many vendors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So hi again :-) &lt;br&gt;
I'm daCoder, this is my new Headless SAAS and this is the story of building it&lt;/p&gt;




&lt;p&gt;Next: &lt;a href="https://dev.to/dacoder/my-own-headless-saas-part-1-where-i-begin-420c"&gt;The beginning&lt;/a&gt;&lt;/p&gt;

</description>
      <category>saas</category>
      <category>headless</category>
      <category>api</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
