Skip to main content

pystockdb

Release Build PyPI - Downloads Coverage Status Codacy Badge

Database for stocks based on pony.orm. This package provides an create, sync and update tool.

At the moment we are only support a few stocks. If you want to have more, please contribute pytickersymbols. Database for stocks this package provides an create, sync and update tool.

install

pip install pystockdb

database schema

StockDB Schema

quick start

In all samples we use sqlite but you are free to use other providers. For more information's please read Connecting to the Database.

Install sqlite stock db:

import logging
from pystockdb.tools.create import CreateAndFillDataBase

logger = logging.getLogger('test')
config = {
    'max_history': 1,
    'indices': ['DAX'],
    'currencies': ['EUR'],
    'create': True,
    'db_args': {
        'provider': 'sqlite',
        'filename': 'demo.sqlite',
        'create_db': True
    },
}
create = CreateAndFillDataBase(config, logger)
create.build()

Install mysql stock db:

For mysql you need an additional package: pip install pymysql

import logging
from pystockdb.tools.create import CreateAndFillDataBase

logger = logging.getLogger('test')
config = {
    'max_history': 1,
    'indices': ['DAX'],
    'currencies': ['EUR'],
    'create': True,
    'db_args': {
        'provider': 'mysql',
        'host': '127.0.0.1',
        'user': 'root',
        'passwd': 'test',
        'db': 'test',
    },
}

create = CreateAndFillDataBase(config, logger)
create.build()

Update sqlite stock db:

import logging
from pystockdb.tools import ALL_SYMBOLS
from pystockdb.tools.update import UpdateDataBaseStocks

logger = logging.getLogger('test')
config = {
    'symbols': [ALL_SYMBOLS],
    'prices': True,       # update prices
    'fundamentals': True, # update fundamental stock data
    'db_args': {
        'provider': 'sqlite',
        'filename': 'demo.sqlite',
        'create_db': False
    },
}
update = UpdateDataBaseStocks(config, logger)
update.build()

Sync sqlite stock db:

import logging
from pystockdb.tools.sync import SyncDataBaseStocks

logger = logging.getLogger('test')
config = {
    'max_history': 1,
    'indices': ['CAC 40'], # add new index to existing database
    'currencies': ['EUR'],
    'db_args': {
        'provider': 'sqlite',
        'filename': 'demo.sqlite',
    },
}
sync = SyncDataBaseStocks(config, logger)
sync.build()

Getting database objects:

import datetime
from pony.orm import db_session

from pystockdb.db.schema.stocks import Price, Stock
from pystockdb.tools.base import DBBase

# connect to database

arguments = {
    'db_args': {
    'provider': 'sqlite',
    'filename': 'test.sqlite',
    'create_db': False
    }
}
# Read https://docs.ponyorm.org/api_reference.html for other provider settings

DBBase(arguments, None)

now = datetime.datetime.now()
last_week = now - datetime.timedelta(days=7)
with db_session:
    # get ifx stock object
    stock = Stock.select(
        (lambda s: 'IFX.F' in s.price_item.symbols.name)
    ).first()
    # select ifx.f prices of the last week
    prices = Price.select(
        lambda p: p.symbol.name == 'IFX.F'
        and p.date >= last_week
        and p.date <= now
    )

issue tracker

https://github.com/portfolioplus/pystockdb/issuese

Metadata

Release files for pystockdb 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pystockdb 1.2.1
File Size Uploaded Provenance
pystockdb-1.2.1.tar.gz 11.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pystockdb 1.2.1
File Interpreter ABI Platform
pystockdb-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.9 kB

Release files / pystockdb-1.2.1.tar.gz

Download URL pystockdb-1.2.1.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3b071db88600fd8ec1dfbd6df0a234337dfa23f4ef9aa409cee3b65e9e879579
BLAKE2b-256 checksum
How to use checksums
9037bfa873c780f8f5e1b50c2aad90d8215408ddfb4476860bbd3314dd36c809
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / pystockdb-1.2.1-py3-none-any.whl

Download URL pystockdb-1.2.1-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88766a25f18854154094708b359176390554a3fed1d183a97231885a6a22894e
BLAKE2b-256 checksum
How to use checksums
ebbc8ee69220d840ead2a5fe06949a8707c73bb8cdefe8ddcfd6c961a70ee2eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Security for pystockdb 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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