Skip to main content

A package consisting of all Tanzania locations from region to streets in a easy accessible way

Project description

mtaa

Downloads Downloads Downloads

A package consisting of all Tanzania locations from region to streets in a easy accessible way made by kalebu

Become a patron

A strory behind

Mtaa package is result of organized json of all the locations in Tanzania, As I was looking for data about these locations data I came across repo tanzania-location-db, It consists of locations data organized into regions, whereby each region has its own csv file. So I wrote a script to transform all the locations from csv into a single Json and from there package came.

Json Transformer

If you wanna give a look at the script or interested about building your Json from a similar kind of raw data here is Json Transformer script.

Installation

Use pip to install it just as shown below;

pip install mtaa

Usage

The library is very straight forward, at the very top of the library is country which is tanzania and at the very bottoms are places in a given street, here is a sample;

>>> from mtaa import tanzania

>>> tanzania
['Shinyanga', 'Mara', 'Dar-es-salaam', 'Kilimanjaro', 'Kagera', 'Tanga', 'Mwanza', 'Tabora', 'Kigoma', 'Pwani', 'Ruvuma', 'Mtwara', 'Morogoro', 'Rukwa', 'Katavi', 'Simiyu', 'Geita', 'Arusha', 'Iringa', 'Mbeya', 'Njombe', 'Manyara', 'Lindi', 'Singida', 'Songwe', 'Dodoma']

>>> tanzania.Mbeya.districts
['Mbeya cbd', 'Mbeya', 'Rungwe', 'Mbarali', 'Kyela', 'Chunya]


>>> tanzania.Mbeya.districts.Rungwe.wards
['ward_post_code', 'Bulyaga', 'Bagamoyo', 'Makandana', 'Msasani', 'Kawetele', 'Itagata', 'Ibigi', 'Kyimo', 'Suma', 'Masoko', 'Mpuguso', 'Malindo', 'Lufingo', 'Kiwira', 'Nkunga', 'Ikuti', 'Kisondela', 'Ilima', 'Bujela', 'Masukulu', 'Kisiba', 'Kabula', 'Lupata', 'Kambasegela', 'Kisegese', 'Itete', 'Lufilyo', 'Lwangwa', 'Mpombo', 'Isange', 'Kandete', 'Luteba', 'Isongole', 'Kinyala', 'Matwebe', 'Masebe', 'Swaya', 'Iponjola', 'Lupepo', 'Ndanto', 'Ntaba', 'Mpata']

How about the Type?

>>> from mtaa import tanzania
>>> type(tanzania)
<class 'mtaa.Tanzania'>

As you can see the repr() being shown on of the REPL is of type <mtaa.Tanzania>, you can easily convert it into native python datatypes due to the fact its iteratable, as shown in the example below;

>>> from mtaa import tanzania
>>> list(tanzania)
['Shinyanga', 'Mara', 'Dar-es-salaam', 'Kilimanjaro', 'Kagera', 'Tanga', 'Mwanza', 'Tabora', 'Kigoma', 'Pwani', 'Ruvuma', 'Mtwara', 'Morogoro', 'Rukwa', 'Katavi', 'Simiyu', 'Geita', 'Arusha', 'Iringa', 'Mbeya', 'Njombe', 'Manyara', 'Lindi', 'Singida', 'Songwe', 'Dodoma']

Since its Iterable that's means you can loop through it, but as string for Example;

>>> for district in tanzania.Mbeya.districts:
...     print(district)
... 
Mbeya cbd
Mbeya
Rungwe
Mbarali
Kyela
Chunya

How about Dar-es-salaam ?

In the above example we were able to retreive locations of Mbeya region because, Mbeya is a valid python identifier, when you try to access Dar-es-Salaam it will ofcourse raise you an error just as shown below;

>>> from mtaa import tanzania
>>> tanzania.Dar-es-salaam
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Tanzania' object has no attribute 'Dar'

To resolve this at anypoint where you a location name is an invalid identifier, use get_dict() instead of (.) operator to access it as shown in the example below;

>>> from mtaa import tanzania 
>>> tanzania.get('Dar-es-salaam').districts
['Ilala cbd', 'Ilala', 'Kinondoni', 'Temeke', 'Ubungo', 'Kigamboni']

Fetching the whole tree

Lets you want to extract no just names in a ward but the whole ward and its deeper roots, to do this use the tree () at any given instance with exception of places in streets which are just list;

Here an example (Some places in Tanzania)

>>> home = tanzania.Mbeya.districts.Rungwe.wards.Kiwira.tree()
>>> print(home)
{'ward_post_code': '53515', 'streets': {'Mpandapanda': ['Ipoma', 'Kiwira kati', 'Mpandapanda', 'Ilongoboto', 'Isange'], 'Kikota': ['Lukwego', 'Lubwe', "Kang'eng'e", 'Ilamba', 'Kikota', 'Ipande'], 'Ibula': ['Kibumbe', 'Ibula', 'Kanyegele', 'Sanu - salala kalongo', 'Katela'], 'Ilundo': ['Bujinga', 'Ibagha a', 'Buswema', 'Ibagha b', 'Kanyambala', 'Lusungo'], 'Ilolo': ['Ibigi', 'Ilolo', 'Itekele', 'Masebe', 'Masugwa', 'Kisungu']}}

Grouped Locations

You can also access grouped locations such as all districts, wards and street as shown below;

>>> import mtaa
>>> mtaa.wards
......
>>> len(mtaa.wards)
3964
>>> mtaa.districts
......
>>> len(mtaa.districts)
158
>>>mtaa.streets
.....
>>> len(mtaa.streets)
16741

From other languages ?

Incase you're from other languages than Python you might wanna take a look at these general purpose APIS

Give it a star

If you found this repository useful, give it a star so as the whole galaxy of developer can get to know it, you can also keep in touch with me on twitter.

Bug bounty?

If you encounter issue with the usage of the package, feel free raise an issue so as we can fix it as soon as possible(ASAP) or just reach me directly through email isaackeinstein(at)gmail.com.

Pull Requests

If you have something to add I welcome pull requests on improvement , you're helpful contribution will be merged as soon as possible

Disclaimer

All the location I used to build this repository, I got from an public repository titled tanzania-locations-db, I'm not responsible for any kind of misinformation in it, I tried to locate my home with it found its pretty accurate, so use it to your own risk

Credits

All the credits to ;

Related Opensource Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mtaa-1.5.tar.gz (369.7 kB view details)

Uploaded Source

Built Distribution

mtaa-1.5-py3-none-any.whl (372.0 kB view details)

Uploaded Python 3

File details

Details for the file mtaa-1.5.tar.gz.

File metadata

  • Download URL: mtaa-1.5.tar.gz
  • Upload date:
  • Size: 369.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for mtaa-1.5.tar.gz
Algorithm Hash digest
SHA256 c70acea1793883c7fe905f41be76345bee82120628d11c4278c8f524c3f7e9ce
MD5 24045468c26adcab10349278df1934f8
BLAKE2b-256 3c55fd4e072ae74c1e455de24d6b3ccdb147c4110f1d60f23e1e44223a179ec0

See more details on using hashes here.

Provenance

File details

Details for the file mtaa-1.5-py3-none-any.whl.

File metadata

  • Download URL: mtaa-1.5-py3-none-any.whl
  • Upload date:
  • Size: 372.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for mtaa-1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7ba89c0674fee198c16a249a4318762d1839a9311ad159e3698fb5c7d28508ec
MD5 951e5a31b48b1caa49f285cd91eaa2c2
BLAKE2b-256 c9c737e2a191d8201ed4acf13a479a163a613c86852606cd9897e619139b9a6c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page