atem18 / isocodes Goto Github PK
View Code? Open in Web Editor NEWThis project provides lists of various ISO standards (e.g. country, language, language scripts, and currency names) in one place
License: GNU Lesser General Public License v2.1
This project provides lists of various ISO standards (e.g. country, language, language scripts, and currency names) in one place
License: GNU Lesser General Public License v2.1
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.github/workflows/publish-test.yaml
actions/checkout v3.2.0
actions/setup-python v4
pypa/gh-action-pypi-publish v1.6.4
.github/workflows/publish.yaml
actions/checkout v3.2.0
actions/setup-python v4
pypa/gh-action-pypi-publish v1.6.4
.github/workflows/test.yaml
actions/checkout v3.2.0
actions/setup-python v4
dev-requirements.txt
anyio ==3.6.2
attrs ==22.2.0
black ==22.12.0
certifi ==2022.12.7
click ==8.1.3
commonmark ==0.9.1
distlib ==0.3.6
editables ==0.3
exceptiongroup ==1.1.0
filelock ==3.9.0
flake8 ==5.0.4
ghp-import ==2.1.0
h11 ==0.14.0
hatch ==1.6.3
hatchling ==1.12.1
httpcore ==0.16.3
httpx ==0.23.2
hyperlink ==21.0.0
idna ==3.4
importlib-metadata ==4.2.0
iniconfig ==1.1.1
jaraco-classes ==3.2.3
jinja2 ==3.0.3
keyring ==23.9.3
markdown ==3.3.4
markupsafe ==2.1.1
mccabe ==0.7.0
mergedeep ==1.3.4
mkdocs ==1.2.4
mkdocs-autorefs ==0.4.1
mkdocs-material ==8.2.7
mkdocs-material-extensions ==1.1.1
mkdocstrings ==0.19.1
more-itertools ==9.0.0
mypy ==0.991
mypy-extensions ==0.4.3
packaging ==22.0
pathspec ==0.10.3
pexpect ==4.8.0
platformdirs ==2.6.2
pluggy ==1.0.0
ptyprocess ==0.7.0
py ==1.11.0
pycodestyle ==2.9.1
pyflakes ==2.5.0
pygments ==2.14.0
pymdown-extensions ==9.9
pyperclip ==1.8.2
pytest ==7.2.0
python-dateutil ==2.8.2
pyyaml ==6.0
pyyaml-env-tag ==0.1
rfc3986 ==1.5.0
rich ==13.0.0
shellingham ==1.5.0
six ==1.16.0
sniffio ==1.3.0
tomli ==2.0.1
tomli-w ==1.0.0
tomlkit ==0.11.6
tox ==3.28.0
typed-ast ==1.5.4
typing-extensions ==4.4.0
userpath ==1.8.0
virtualenv ==20.16.2
watchdog ==2.2.1
zipp ==3.11.0
Example:
>>> from isocodes import countries
>>> countries.get(alpha_2='VE')
{'alpha_2': 'VE', 'alpha_3': 'VEN', 'common_name': 'Venezuela', 'flag': 'π»πͺ', 'name': 'Venezuela, Bolivarian Republic of', 'numeric': '862', 'official_name': 'Bolivarian Republic of Venezuela'}
>>> countries.get(common_name='Venezuela')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/quan/Works/Envs/vieperid/lib/python3.10/site-packages/isocodes/__init__.py", line 30, in get
return [element for element in self.data if element[key] == kwargs[key]][0]
File "/home/quan/Works/Envs/vieperid/lib/python3.10/site-packages/isocodes/__init__.py", line 30, in <listcomp>
return [element for element in self.data if element[key] == kwargs[key]][0]
KeyError: 'common_name'
'common_name'
Would you accept a PR to include a PyInstaller hook in this repository?
Thank you for pushing pycountry
into the future!! I have a bug to report.
Using latest isocodes
, Python 3.11.4
import isocodes
assert isocodes.languages.get(name="Spanish")
^ the assert fails.
Direct string matches are a pain π
Here's the line that shows the data has "Spanish; ..." rather than "Spanish" alone. Something like iso639's match
functionality would supercharge this library.
Currently isocodes does not work with PyInstaller 6.2.0.
importlib.resources is available for Python >=3.9 for Python 3.8 isocodes can either depend on the importlib_metadata>=1.3 backport package or fall back to file which does work with PyInstaller.
Using importlib.resources would also make isocodes compatible with more exotic python loaders with minimal effort https://pyoxidizer.readthedocs.io/en/v0.6.0/packaging_pitfalls.html (yes pyoxidizer is on 0.23.0 and now supports the __file__
attribute for loading filesystem resources, but the information is still valid, later documentation splits it up into several different pages)
I can open a pull request if you would like
An example of how this could be implemented:
def get_resource(resource: str) -> 'importlib.resources.abc.Traversable':
"""Return a file handle on a named resource in a Package."""
# Attempt impotlib.resources
if sys.version_info >= (3, 9):
import importlib.resources
return importlib.resources.files('isocodes').joinpath(resource)
# Attempt importlib_resources backport
try:
if sys.version_info < (3, 9):
import importlib_resources
return importlib_resources.files('isocodes').joinpath(resource)
except ImportError:
...
# Fall back to __file__.
# Undefined __file__ will raise NameError on variable access.
try:
package_path = os.path.abspath(os.path.dirname(__file__))
except NameError:
package_path = None
if package_path is not None:
resource_path = os.path.join(package_path, resource)
return pathlib.Path(resource_path)
# Could not resolve package path from __file__.
raise Exception(f'do not know how to load resource: {resource}')
class ISO:
iso_key: str
data: List[Dict[str, str]]
def __init__(self, iso_key: str) -> None:
self.iso_key = iso_key
with get_resource(
f"share/iso-codes/json/iso_{self.iso_key}.json"
).open(encoding="utf-8") as iso_file:
self.data = json.load(iso_file)[self.iso_key]
Here is a reproducible example
$ pyinstaller main.py --collect-data isocodes
$ dist/main/main
Traceback (most recent call last):
File "main.py", line 1, in <module>
import isocodes
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "isocodes/__init__.py", line 317, in <module>
File "isocodes/__init__.py", line 92, in __init__
FileNotFoundError: [Errno 2] No such file or directory: '/home/lordwelch/isocodes/dist/main/share/iso-codes/json/iso_3166-1.json'
[28509] Failed to execute script 'main' due to unhandled exception!
main.py:
import isocodes
print('success')
Countries change names from time to time. For example, Swaziland changed its name to Eswatini in 2018, but kept their country code (SWZ). "Swaziland" doesn't appear in countries
or former_countries
, so it's not possible to look up the country code based on old data without a separate look-up table.
It would be nice to have a mechanism for looking up countries by their former names.
isocodes
package doesnβt use encoding="utf-8"
to read the json files in the ISO.__init.py which is causing issues on Windows as the default Python encoding on Windows is not UTF-8.
C:\Anaconda3\lib\site-packages\isocodes\__init__.py in <module>
217 languages = Languages("639-2")
218 currencies = Currencies("4217")
--> 219 subdivisions_countries = SubdivisionsCountries("3166-2")
220 former_countries = FormerCountries("3166-3")
221 extendend_languages = ExtendedLanguages("639-3")
C:\Anaconda3\lib\site-packages\isocodes\__init__.py in __init__(self, iso_key)
27 f"{BASE_DIR}/share/iso-codes/json/iso_{self.iso_key}.json"
28 ) as iso_file:
---> 29 self.data: List[Dict] = json.load(iso_file)[self.iso_key]
30
31 def __len__(self) -> int:
C:\Anaconda3\lib\json\__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
291 kwarg; otherwise ``JSONDecoder`` is used.
292 """
--> 293 return loads(fp.read(),
294 cls=cls, object_hook=object_hook,
295 parse_float=parse_float, parse_int=parse_int,
C:\Anaconda3\lib\encodings\cp1252.py in decode(self, input, final)
21 class IncrementalDecoder(codecs.IncrementalDecoder):
22 def decode(self, input, final=False):
---> 23 return codecs.charmap_decode(input,self.errors,decoding_table)[0]
24
25 class StreamWriter(Codec,codecs.StreamWriter):
class ISO:
def __init__(self, iso_key: str) -> None:
self.iso_key: str = iso_key
with open(
f"{BASE_DIR}/share/iso-codes/json/iso_{self.iso_key}.json", encoding="utf-8"
) as iso_file:
self.data: List[Dict] = json.load(iso_file)[self.iso_key]`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.