Skip to main content

fastcat

Tests Publish PyPI Python Versions Downloads License Pending Pull-Requests Github Issues Commits Since Release

Fastcat is a little Python library for quickly looking up broader/narrower relations in Wikipedia categories locally. The idea is that fastcat can be useful in situations where you need to rapidly lookup category relations, but don't want to hammer on the Wikipedia API. Fastcat relies on Redis and the SKOS file that DBpedia makes available basing on the Wikipedia MySQL dumps.

fastcat logo

Attribution

This software is a fork of fastcat tool created by Ed Summers. Some changes were made under the Creative Commons Attribution-ShareAlike 3.0 license, and they are described in commit messages. Major changes are porting the code to Python 3 as well as adding support for more than one language.

Usage

Basic usage

The first time you import fastcat you'll need to populate your Redis database with the category data from DBpedia. To do that instantiate a FastCat object and call the load method. After that you can use it to do lookups.

>>> import fastcat
>>> f = fastcat.FastCat()
>>> f.load()  # brew a pot of coffee while the data is downloaded and loaded into redis
...
>>> print(f.broader("Computer programming"))
['Software engineering', 'Computing']
>>> print(f.narrower("Computer programming"))
['Programming idioms', 'Programming languages', 'Concurrent computing', 'Source code', 'Refactoring', 'Data structures', 'Programming games', 'Computer programmers', 'Version control', 'Anti-patterns', 'Programming constructs', 'Algorithms', 'Web Services tools', 'Programming paradigms', 'Software optimization', 'Debugging', 'Computer programming tools', 'Computer libraries', 'Programming contests', 'Archive networks', 'Self-hosting software', 'Educational abstract machines', 'Software design patterns', 'Computer arithmetic']

Non-english categories

Just fill-in the language argument in the FastCat() constructor with a language code listed below.

>>> import fastcat
>>> f = fastcat.FastCat(language='de')
>>> f.load()  # brew a pot of coffee while the data is downloaded and loaded into redis
...
>>> print(f.broader("Berlin"))
['Europa nach Ort', 'Deutschland nach Gemeinde', 'Deutschland nach Bundesland']
>>> print(f.narrower("Berlin"))
['Umwelt- und Naturschutz (Berlin)', 'Veranstaltung (Berlin)', 'Stadtplanung (Berlin)', 'Verwaltung (Berlin)', 'Urbaner Freiraum in Berlin als Thema']
Currently supported languages (and their codes)
  1. English (en)
  2. Estonian (et)
  3. German (de)
  4. Japanese (ja)
  5. Polish (pl)
  6. Portuguese (pt)
  7. Russian (ru)
  8. Ukrainian (ua)
  9. Czech (cs)

Install

Redis installation

You first need to setup Redis server on your machine as follows.

On Mac:

$ brew install redis

On Linux:

$ sudo apt-get install redis-server

On Windows:

Please refer to instruction on installing Vagrant Redis. You will need an Ubuntu installation on your Windows, more information can be found here: Install your Linux Distribution of Choice

With Docker (any platform):

If you would rather not install Redis at all, the bundled compose file spins one up on localhost:6379, with the loaded categories kept in a named volume so they survive a restart:

$ docker compose up -d redis

The same file also defines a fastcat container with the package and its dev dependencies installed, which is handy for running the suite in a clean environment:

$ docker compose run --rm fastcat pytest

Inside a container Redis is not on localhost, so fastcat reads the FASTCAT_REDIS_HOST and FASTCAT_REDIS_PORT environment variables (already set for the fastcat service) to find it.

Installing the module

If you are ready, installing Fastcat is pretty straightforward:

$ pip install fastcat

Or if you wish to get the newest dev code:

$ pip install git+https://github.com/oskar-j/fastcat.git

That's it!

Contributing to the project

Guidelines

See CONTRIBUTING.md for more details

Running unit tests

With uv, which installs the exact versions from the committed uv.lock:

$ uv sync
$ uv run pytest

Or with pip:

$ pip install -e '.[dev]'
$ pytest

That runs the fast, offline tests. The end-to-end tests need a Redis server and download a SKOS dump per language from DBpedia, so they are opt-in:

$ docker compose up -d redis      # or your own local Redis
$ pytest --run-integration

Q&A

How much is is tested?

It's still in early stage of development, please share some feedback with me (under the ticket #7).

What are biggest drawbacks of Fastcat?

DBpedia SKOS file is prone to constant change, which means that downloading Wikipedia data from web can stop working in some distant future. Moreover, due to the infrastructure of Redis, you can have a maximum number of 16 languages (1 slot for a language). Last but not least, it takes around 40 MB of your web transfer (size depends on the selected language) to download a single SKOS file.

Which Python versions are supported?

Python 3.10 and above (tested on GitHub Actions against 3.10 through 3.14). Releases up to 0.1.2 supported Python 3.5+; if you are stuck on an older interpreter, pin fastcat==0.1.2.

Which languages are supported?

There are two ways to check the list of available languages.

First, is a manual inspection of the lang.py file.

Second way is to call the get_supported_languages() method on the FastCat object.

What's coming next?

Support for the rest of european languages. Exporting n-size tree of categories to a CSV or GraphML file. Moving the downloaded dumps and the language mapping out of the package directory into a proper user cache directory.

License

Creative Commons Attribution-ShareAlike 3.0

Download files

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

Source Distribution

fastcat-0.2.2.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastcat-0.2.2-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file fastcat-0.2.2.tar.gz.

File metadata

  • Download URL: fastcat-0.2.2.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fastcat-0.2.2.tar.gz
Algorithm Hash digest
SHA256 123758d1b24408dac8258d7515d88b0acf5ebb722b8213bc7059d0748d00ba22
MD5 16bc4a5f033deeeded1a0819fe881ecb
BLAKE2b-256 427f610bada6da000fea282c039f5f297bb727756f731fb012ceb391c51f159d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastcat-0.2.2.tar.gz:

Publisher: publish.yml on oskar-j/fastcat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastcat-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: fastcat-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fastcat-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0944ede6970a06b7603f0c61c488733b19ea693c4ef638f3ddb0f3f198a761db
MD5 67619bd3b1ef5baffa98925c7b6de952
BLAKE2b-256 5c6ed5e1d15dca1120c3f819f2dafe5dffd86feabb4d7b5d876d4db3ef9497ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastcat-0.2.2-py3-none-any.whl:

Publisher: publish.yml on oskar-j/fastcat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.0

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

This release

0.2.2 This release

2 files

0.2.1

2 files

0.1.2

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page