Skip to main content

pytickersymbols provides access to google and yahoo ticker symbols

Project description

Release Build PyPI - Downloads Coverage Status Codacy Badge

pytickersymbols

pytickersymbols provides access to google and yahoo ticker symbols for all stocks of the following indices:

  • AEX
  • BEL 20
  • CAC 40
  • CAC MID 60
  • DAX
  • DOW JONES
  • EURO STOXX 50
  • FTSE 100
  • IBEX 35
  • MDAX
  • NASDAQ 100
  • OMX Helsinki 25
  • OMX Stockholm 30
  • S&P 100
  • S&P 500
  • S&P 600
  • SDAX
  • Switzerland 20
  • TECDAX

install

pip3 install pytickersymbols

quick start

Get all countries, indices and industries as follows:

from pytickersymbols import PyTickerSymbols

stock_data = PyTickerSymbols()
countries = stock_data.get_all_countries()
indices = stock_data.get_all_indices()
industries = stock_data.get_all_industries()

You can select all stocks of an index as follows:

from pytickersymbols import PyTickerSymbols

stock_data = PyTickerSymbols()
german_stocks = stock_data.get_stocks_by_index('DAX')
uk_stocks = stock_data.get_stocks_by_index('FTSE 100')

print(list(uk_stocks))

If you are only interested in ticker symbols, then you should have a look at the following lines:

from pytickersymbols import PyTickerSymbols

stock_data = PyTickerSymbols()
# the naming conversation is get_{index_name}_{exchange_city}_{yahoo or google}_tickers
dax_google = stock_data.get_dax_frankfurt_google_tickers()
dax_yahoo = stock_data.get_dax_frankfurt_yahoo_tickers()
sp100_yahoo = stock_data.get_sp_100_nyc_yahoo_tickers()
sp500_google = stock_data.get_sp_500_nyc_google_tickers()
dow_yahoo = stock_data.get_dow_jones_nyc_yahoo_tickers()
# there are too many combination. Here is a complete list of all getters
all_ticker_getter_names = list(filter(
   lambda x: (
         x.endswith('_google_tickers') or x.endswith('_yahoo_tickers')
   ),
   dir(stock_data),
))
print(all_ticker_getter_names)

Iterator Examples

Use iterator-based APIs to stream results without building large lists:

from pytickersymbols import PyTickerSymbols

stock_data = PyTickerSymbols()

# Stream indices
for index in stock_data.iter_all_indices():
   print(index)

# Stream all unique stocks
for company in stock_data.iter_all_stocks():
   print(company['name'])

# Stream industries and countries
for industry in stock_data.iter_all_industries():
   pass  # handle industry
for country in stock_data.iter_all_countries():
   pass  # handle country

# Stream Yahoo tickers for an index (flattened)
for tickers in stock_data.iter_yahoo_ticker_symbols_by_index('DAX'):
   for ticker in tickers:
      print(ticker)

# Stream tickers using exchange-specific dynamic methods
for ticker in stock_data._iter_tickers_by_index('DAX', ('FRA:',), 'yahoo'):
   print(ticker)

Development

Setting up the development environment

This project uses Poetry for dependency management. To set up your development environment:

# Install Poetry if you haven't already
curl -sSL https://install.python-poetry.org | python3 -

# Clone the repository
git clone https://github.com/portfolioplus/pytickersymbols.git
cd pytickersymbols

# Install dependencies (including dev dependencies)
poetry install

# Activate the virtual environment
poetry shell

Development Tools

The tools/ directory contains scripts for managing stock index data:

  • build_indices.py: End-to-end pipeline to parse Wikipedia, enrich with stocks.yaml, canonicalize names, and generate the Python data module.
  • wiki_table_parser.py: Utilities to parse Wikipedia tables configured via index_sources.yaml.
  • enrich_indices.py: Merge raw parsed data with stocks.yaml historical metadata and symbols.
  • canonicalize_names.py: Normalize company display names across indices using ISIN/Wikipedia.
  • sync_canonical_to_stocks.py: Propagate canonical names back to stocks.yaml.
  • enrich_with_yfinance.py: Optional enrichment helpers using Yahoo Finance.

See tools/README.md for detailed usage instructions.

Running Tests

poetry run pytest

Adding a New Index

To add a new stock index to the library:

  1. Add the index to configuration
    Edit tools/index_sources.yaml and add a new entry:

    - name: NIKKEI 225
      source:
        type: wikipedia
        url: https://en.wikipedia.org/wiki/Nikkei_225
        table_title_regex: "Components"
        extract_company_info: true
        language_fallbacks: ["ja", "en"]
        columns:
          name: ["Company", "Name"]
          symbol: ["Ticker", "Symbol"]
          isin: ["ISIN"]
          sector: ["Sector", "Industry"]
        symbol_converter:
          - pattern: "^(.+)$"
            format: "{1}.T"  # Add .T suffix for Tokyo Stock Exchange
      match:
        by: symbol
    

    Configuration options:

    • name: Display name (must match stocks.yaml if merging with historical data)
    • url: Wikipedia page URL containing the index constituents table
    • table_title_regex: (Optional) Regex to match the table title
    • extract_company_info: Set to true to fetch additional details from company Wikipedia pages
    • language_fallbacks: List of Wikipedia language codes to try for ISIN lookup
    • symbol_converter: Rules to convert Wikipedia symbols to Yahoo Finance format
    • columns: Map Wikipedia table headers to data fields
    • match.by: Field to use for matching with historical data (symbol, isin, or name)
  2. Run the build pipeline
    This will parse Wikipedia, enrich the data, and generate the Python module:

    cd tools
    python build_indices.py
    

    This creates:

    • indices_raw/<index_name>.json - Raw parsed data from Wikipedia
    • indices/<index_name>.yaml - Enriched data merged with historical records
    • Updates src/pytickersymbols/indices_data.py - Generated Python module
  3. Test the new index
    Verify the index is accessible:

    from pytickersymbols import PyTickerSymbols
    
    stock_data = PyTickerSymbols()
    nikkei_stocks = stock_data.get_stocks_by_index('NIKKEI 225')
    print(list(nikkei_stocks))
    
  4. Run tests
    Ensure everything works:

    poetry run pytest
    
  5. Update the index list
    Add a checkbox entry to the supported indices list at the top of this README.

Note: The build pipeline automatically runs weekly via GitHub Actions to keep index data up to date.

Performance Tips

  • Lookups for stocks by symbol and aggregated lists/sets are internally cached for speed. After calling load_json() or load_yaml(), caches are automatically rebuilt.
  • For large results, prefer generator variants to avoid materializing lists: iter_all_indices(), iter_all_stocks(), iter_all_countries(), iter_all_industries(), and iter_yahoo_ticker_symbols_by_index() / iter_google_ticker_symbols_by_index().
  • Dynamic ticker getters follow the naming convention get_{index_name}_{exchange_city}_{yahoo|google}_tickers and return lists. Use _iter_tickers_by_index() for streaming if needed.

issue tracker

https://github.com/portfolioplus/pytickersymbols/issues

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pytickersymbols-1.17.9.tar.gz (401.4 kB view details)

Uploaded Source

Built Distribution

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

pytickersymbols-1.17.9-py3-none-any.whl (406.5 kB view details)

Uploaded Python 3

File details

Details for the file pytickersymbols-1.17.9.tar.gz.

File metadata

  • Download URL: pytickersymbols-1.17.9.tar.gz
  • Upload date:
  • Size: 401.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytickersymbols-1.17.9.tar.gz
Algorithm Hash digest
SHA256 d84ad92018bcebe1e419b104b5c7b209ee7faf16973f59ee4a5434a19667e7b9
MD5 fc02a2fde75238d1181f19e3dbbf46c8
BLAKE2b-256 7cc38df83a45ca3c1b4dfa72558f4b68b74e37006cbed3642fd4fc24e518dc18

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytickersymbols-1.17.9.tar.gz:

Publisher: release.yml on portfolioplus/pytickersymbols

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

File details

Details for the file pytickersymbols-1.17.9-py3-none-any.whl.

File metadata

File hashes

Hashes for pytickersymbols-1.17.9-py3-none-any.whl
Algorithm Hash digest
SHA256 9d03b925adcdbc59c24350b2451429daa4365e0c761d7b16ebe039bc272837be
MD5 ade87f1cc8fd8ed7d7c0cc8ca9d2686c
BLAKE2b-256 31a54bb8ed5bfbb81c62485cab30ff75e5cceb474edcf7b09471cffa04e18402

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytickersymbols-1.17.9-py3-none-any.whl:

Publisher: release.yml on portfolioplus/pytickersymbols

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

Supported by

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