Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brain-facens/br-address-parser
A simple parser for brazilian addresses
https://github.com/brain-facens/br-address-parser
Last synced: 1 day ago
JSON representation
A simple parser for brazilian addresses
- Host: GitHub
- URL: https://github.com/brain-facens/br-address-parser
- Owner: brain-facens
- License: mit
- Created: 2021-07-13T20:21:15.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-27T18:20:07.000Z (over 1 year ago)
- Last Synced: 2024-09-25T09:11:56.308Z (about 2 months ago)
- Language: Python
- Size: 11.7 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# br-address-parser
This module is a simple parser for Brazilian addresses. This receives a complete address string and split it in 'street', 'number', 'complement', 'neighborhood', 'city' and 'state'.This code is a [br-address-parser](https://github.com/Minutrade/br-address-parser) port for Python.
Credits should go to the original implementation contributors.## How to install
```
pip install br_address_parser
```## How to use
```py
from br_address_parser import parsecomplete_address = "Av. Brasil, 1245 - Bloco 2 Ap 203 - Centro - Belo Horizonte - MG"
parsed_address = parse(complete_address)
```The above example transforms the string "Av. Brasil, 1245 - Bloco 2 Ap 203 - Centro - Belo Horizonte - MG" into the following object:
```json
{
"street": "Av. Brasil",
"number": "1245",
"complement": "Bloco 2 Ap 203",
"neighborhood": "Centro",
"city": "Belo Horizonte",
"state": "MG"
}
```If you want to fill some fields with default values when they are empty, then you can use `defaultFields` parameter:
```py
complete_address = "AV ANAVILLE 1-QD 3 LT 4 - RESIDENCIAL ANAVILLE - ANAPOLIS - GO"
parsed_address = parse(complete_address, {"number": "S/N"})
```The above example transforms will put `S/N` in the `number` field, because parsed address returns empty `number`:
```json
{
"street": "AV ANAVILLE 1",
"number": "S/N",
"complement": "QD 3 LT 4",
"neighborhood": "RESIDENCIAL ANAVILLE",
"city": "ANAPOLIS",
"state": "GO"
}
```When the address cannot be parsed, the `parse` function returns `None`.
## How to test
```
make test
```## License
This project is licensed under the terms of the MIT license.